home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / HRTmon / src / HRTmonV2.s < prev    next >
Text File  |  1999-11-06  |  212KB  |  11,346 lines

  1.  
  2. ;HRTmon Amiga system monitor
  3. ;Copyright (C) 1991-1998 Alain Malek Alain.Malek@cryogen.com
  4. ;
  5. ;This program is free software; you can redistribute it and/or
  6. ;modify it under the terms of the GNU General Public License
  7. ;as published by the Free Software Foundation; either version 2
  8. ;of the License, or (at your option) any later version.
  9. ;
  10. ;This program is distributed in the hope that it will be useful,
  11. ;but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;GNU General Public License for more details.
  14. ;
  15. ;You can find the full GNU GPL online at: http://www.gnu.org
  16.  
  17.  
  18. *******************************
  19. **        HRTmon v2.17       **
  20. *******************************
  21. **   code by Alain Malek    ***
  22. *******************************
  23.  
  24. ***********************************************************
  25.  
  26.     IFD BARFLY
  27.         MC68030
  28.         SUPER            ;disable supervisor warnings
  29.         BOPT w4-        ;disable 64k warnings
  30.         OUTPUT "hrtmon.data.basm"
  31.  
  32. OPT_OFF        MACRO
  33.         BOPT OD6-        ;disable branch optimizing
  34.         ENDM
  35. OPT_ON        MACRO
  36.         BOPT OD6+        ;enable branch optimizing
  37.         ENDM
  38.  
  39.     ENDC
  40.  
  41.     IFD _PHXASS_
  42.         MC68030
  43.         OPT NBL
  44.  
  45. OPT_OFF        MACRO
  46.         OPT 0
  47.         ENDM
  48. OPT_ON        MACRO
  49.         OPT NBL
  50.         ENDM
  51.  
  52.     ENDC
  53.  
  54.     IFND BARFLY
  55.     IFND _PHXASS_
  56.  
  57. MC68030    MACRO
  58.     ENDM
  59. MC68040    MACRO
  60.     ENDM
  61.  
  62. OPT_ON    MACRO
  63.     ENDM
  64. OPT_OFF    MACRO
  65.     ENDM
  66.  
  67.     ENDC
  68.     ENDC
  69.  
  70. ***********************************************************
  71.  
  72.  
  73. SC_STEP equ 16        ;fast scrolling step
  74.  
  75. LOSIZE equ $9800    ;size of lowmem backuped
  76.  
  77. MAX_SCREEN equ 52
  78.  
  79. version    macro
  80.     dc.b "2.17"
  81.     endm
  82.  
  83.     incdir include:
  84.     include exec/tasks.i
  85.     include hardware/custom.i
  86.  
  87. ***********************************************************
  88.  
  89.     include exec/types.i
  90.     include exec/execbase.i
  91.     include devices/hardblocks.i
  92.  
  93.     incdir hrt:
  94.  
  95. ***********************************************************
  96. ;-------------- MACRO same as corr_addr subroutine --------
  97.  
  98. CORR_ADDR:    macro
  99.         clr.l    corr_val
  100.         cmpa.l    #LOSIZE-64,a4
  101.         bge.b    .ok_low\1
  102.         add.l    #backup_pic,a4
  103.         move.l    #backup_pic,corr_val
  104. .ok_low\1:
  105.         endm
  106.  
  107. ***********************************************************
  108.  
  109. start        ;bra.w    monitor
  110.         moveq    #0,d0
  111.         rts
  112.         dc.b "HRT!"        ;4
  113.  
  114.     OPT_OFF
  115.         bra.w    mon_install    ;8  jmp to install routine
  116.         bra.w    monitor        ;12 jmp to monitor
  117.         bra.w    mon_remove    ;16 jmp to remove routine
  118.     OPT_ON
  119. mon_size    dc.l 0            ;20 size of HRTmon (for FreeMem)
  120. config_RM    dc.b 0            ;24 -1=right-mouse enter on 0=off
  121. config2        dc.b 0            ;25 no of keyboard to use
  122. config_key    dc.b 0            ;26 -1= \ key enter on 0=off
  123. config_IDE    dc.b 0            ;27 -1= IDE harddisk
  124. config_A1200    dc.b 0            ;28 -1= A1200
  125. config_AGA    dc.b 0            ;29 -1= AGA
  126. config_insert    dc.b 0            ;30 -1= insert
  127. config_delay    dc.b 15            ;31 repeat key delay (default = 15)
  128. config_lview    dc.b 0            ;32 -1= lview task
  129. config_elsat    dc.b 0            ;33 -1=elsat.device IDE (CD32)
  130. config_screen    dc.b 0            ;34 screen mode no 0=PAL,1=NTSC,2=MULTISCAN
  131.         even
  132.  
  133.  
  134. mon_remove    movem.l    d1-a6,-(a7)
  135.         move.l    $4.w,a6
  136.         lea.l    .super(pc),a5
  137.         jsr    -30(a6)
  138.  
  139.         move.l    mon_size(pc),d0
  140.         beq.b    .nofree
  141.         lea.l    start(pc),a1
  142.         jsr    -210(a6)    ;FreeMem
  143. .nofree
  144.         tst.b    config_lview
  145.         beq.b    .nolview
  146.         move.l    $4.w,a6
  147.         move.l    gfxbase(pc),a1
  148.         jsr    -414(a6)
  149.  
  150.         lea.l    tc_block(pc),a1
  151.         jsr    -288(a6)    ;RemTask
  152.  
  153. .nolview
  154.         movem.l    (a7)+,d1-a6
  155.         moveq    #0,d0
  156.         rts
  157.  
  158. .super        movec    VBR,a4
  159.         move.l    oldlev7(pc),$7c(a4)
  160.         move.l    old_vbr(pc),a4
  161.         movec    a4,VBR
  162.         rte
  163.  
  164. mon_install    movem.l    d1-a6,-(a7)
  165.  
  166.         lea.l    start(pc),a0
  167.  
  168.         move.w    #28,screen_height
  169.         cmp.b    #1,config_screen
  170.         bne.b    .nontsc
  171.         move.w    #22,screen_height
  172. .nontsc        cmp.b    #2,config_screen
  173.         bne.b    .nomulti
  174.         move.w    #52,screen_height
  175. .nomulti
  176.  
  177.         move.w    #MAX_SCREEN,d2
  178.         sub.w    screen_height,d2
  179.         mulu    #80,d2
  180.         move.l    d2,d1
  181.         add.l    #ascII_page1,d1
  182.         move.l    d1,ascII_ptr
  183.         move.l    d1,ascII_ptr+4
  184.         move.l    d2,d1
  185.         add.l    #ascII_page2,d1
  186.         move.l    d1,ascII_ptr+8
  187.         move.l    d2,d1
  188.         add.l    #ascII_Tracer,d1
  189.         move.l    d1,ascII_ptr+12
  190.  
  191.         move.w    screen_height,d1
  192.         subq.w    #4,d1
  193.         move.w    d1,window_bot
  194.  
  195.         move.l    a0,location
  196.  
  197.         move.l    $4.w,a6
  198.         move.l    MaxLocMem(a6),max_chip
  199.  
  200.         lea.l    .super(pc),a5
  201.         jsr    -30(a6)
  202.  
  203.         tst.b    config_IDE
  204.         beq.w    .noide
  205.  
  206.         tst.b    config_elsat
  207.         beq.b    .noelsat
  208.  
  209.         move.l    #$eb8000,ide_base
  210.         clr.l    ide_irq
  211.         move.w    #$0,ide_data
  212.         move.w    #$100,ide_error
  213.         move.w    #$100,ide_feature
  214.         move.w    #$200,ide_secnt
  215.         move.w    #$300,ide_secnb
  216.         move.w    #$400,ide_cyllo
  217.         move.w    #$500,ide_cylhi
  218.         move.w    #$600,ide_dhead
  219.         move.w    #$700,ide_status
  220.         move.w    #$700,ide_command
  221.         move.w    #$4600,ide_altstat
  222.         bra.w    .noide
  223.  
  224. .noelsat    move.w    #$0,ide_data
  225.         move.w    #$4,ide_error
  226.         move.w    #$4,ide_feature
  227.         move.w    #$8,ide_secnt
  228.         move.w    #$c,ide_secnb
  229.         move.w    #$10,ide_cyllo
  230.         move.w    #$14,ide_cylhi
  231.         move.w    #$18,ide_dhead
  232.         move.w    #$1c,ide_status
  233.         move.w    #$1c,ide_command
  234.         move.w    #$1c,ide_altstat
  235.  
  236.         move.l    #$da2000,ide_base
  237.         move.l    #$da9000,ide_irq
  238.         tst.b    config_A1200        ;A1200 ?
  239.         bne.b    .noide
  240.         move.l    #$dd2020,ide_base
  241.         move.l    #$dd3020,ide_irq
  242. .noide
  243.         move.b    config_insert(pc),insert_mode
  244.  
  245.         moveq    #0,d0
  246.         move.b    config2,d0        ;keyboard map
  247.         mulu    #12,d0
  248.         movem.l    .map(pc,d0.l),d0-d2
  249.         movem.l    d0-d2,board_ptr
  250.  
  251.         tst.b    config_lview
  252.         beq.b    .nolview
  253.         lea.l    gfxname(pc),a1
  254.         moveq    #0,d0
  255.         move.l    $4.w,a6
  256.         jsr    -552(a6)
  257.         move.l    d0,gfxbase
  258.  
  259.         move.l    #lview_name,tc_block+LN_NAME
  260.         move.b    #NT_TASK,tc_block+LN_TYPE
  261.         move.b    #8,tc_block+LN_PRI
  262.         move.l    #task_stackend,tc_block+TC_SPREG
  263.         move.l    #task_stack,tc_block+TC_SPLOWER
  264.         move.l    #task_stackend,tc_block+TC_SPUPPER
  265.  
  266.         lea.l    tc_block(pc),a1
  267.         lea.l    task_code(pc),a2
  268.         sub.l    a3,a3
  269.         jsr    -282(a6)        ;AddTask
  270.  
  271. .nolview
  272.         movem.l    (a7)+,d1-a6
  273.         moveq    #0,d0
  274.         rts
  275.  
  276.         cnop 0,4
  277.  
  278. .map        dc.l board3, board4, board4a
  279.         dc.l board1, board2, board2a
  280.         dc.l board5, board6, board6a
  281.         dc.l board7, board8, board8a
  282.  
  283.  
  284. .super        bsr    test_CPU
  285.         move.w    d0,proc_type
  286.  
  287.         movec    VBR,a4
  288.         move.l    a4,old_vbr
  289.         lea.l    new_except,a0
  290.  
  291.         move.l    a0,a1
  292.         lea.l    except_entry(pc),a2
  293.         move.w    #$400/4-1,d1
  294. .init        move.l    a2,(a1)+
  295.         dbf    d1,.init
  296.  
  297.         suba.l    a1,a1
  298.         move.w    #$400/4-1,d1
  299. .copy        move.l    (a4)+,(a1)+
  300.         dbf    d1,.copy
  301.  
  302.         move.l    $7c(a0),oldlev7
  303.         move.l    #monitor,$7c(a0)
  304.         movec    a0,VBR
  305.         move.l    #zlevel7,$7c.w
  306.  
  307.         rte
  308.  
  309. zlevel7:    movem.l    a0,-(a7)
  310.         lea.l    new_except,a0
  311.         movec    a0,VBR
  312.         movem.l    (a7)+,a0
  313.         jmp    monitor
  314.  
  315.         cnop    0,4
  316. gfxbase        dc.l 0
  317. wbview        dc.l 0
  318. signal_no    dc.l 0
  319. changed_disk    dcb.l 16,0
  320. gfxname        dc.b "graphics.library",0
  321. ;dosname        dc.b "dos.library",0
  322. lview_name    dc.b "HRTmon system task",0
  323.  
  324.         cnop    0,4
  325. tc_block    dcb.b TC_SIZE,0
  326. task_stack    dcb.b $400,0
  327. task_stackend
  328.  
  329. task_code
  330.         move.l    $4.w,a6
  331.         moveq    #-1,d0
  332.         jsr    -330(a6)        ; AllocSignal
  333.         move.l    d0,signal_no
  334.  
  335. .loop        move.l    signal_no(pc),d0
  336.         move.l    $4.w,a6
  337.         jsr    -318(a6)        ; Wait
  338.  
  339.         move.l    gfxbase(pc),a6
  340.  
  341.         move.l    wbview(pc),a1
  342.         jsr    -222(a6)         ; LoadView Fix view
  343.         move.l    38(a6),$dff080        ; Kick it into life
  344.  
  345.  
  346.     bra.b    .loop
  347.  
  348. ;experimental code removed should be done from a PROCESS
  349.  
  350. ;        move.l    $4.w,a6
  351. ;        lea.l    dosname(pc),a1
  352. ;        moveq    #0,d0
  353. ;        jsr    -552(a6)
  354. ;        tst.l    d0
  355. ;        beq.b    .nodos
  356. ;        move.l    d0,a6
  357. ;
  358. ;        lea.l    changed_disk(pc),a4
  359. ;        moveq    #16-1,d7
  360. ;.next        move.l    (a4)+,d0
  361. ;        beq.b    .empty
  362. ;
  363. ;        move.l    d0,a0
  364. ;        lea.l    part_name2(a0),a0
  365. ;        moveq    #0,d0
  366. ;        lea.l    .tmp_name(pc),a1
  367. ;        move.b    (a0)+,d0
  368. ;.copy        move.b    (a0)+,(a1)+
  369. ;        dbf    d0,.copy
  370. ;        move.b    #':',(a1)+
  371. ;        sf    (a1)+
  372. ;
  373. ;        clr.l    -4(a4)
  374. ;
  375. ;        move.l    d7,-(a7)
  376. ;
  377. ;        move.l    #.tmp_name,d1
  378. ;        jsr    -174(a6)        ; DeviceProc
  379. ;        tst.l    d0
  380. ;        beq.b    .err
  381. ;        move.l    d0,a3
  382. ;        move.l    a3,d1
  383. ;        moveq    #$1f,d2
  384. ;        moveq    #-1,d3
  385. ;        moveq    #0,d4
  386. ;        moveq    #0,d5
  387. ;        moveq    #0,d6
  388. ;        moveq    #0,d7
  389. ;        jsr    -240(a6)        ; DoPkt
  390. ;        tst.l    d0
  391. ;        beq.b    .err
  392. ;        move.l    a3,d1
  393. ;        moveq    #$1f,d2
  394. ;        moveq    #0,d3
  395. ;        moveq    #0,d4
  396. ;        moveq    #0,d5
  397. ;        moveq    #0,d6
  398. ;        moveq    #0,d7
  399. ;        jsr    -240(a6)        ; DoPkt
  400. ;.err
  401. ;        move.l    (a7)+,d7
  402. ;
  403. ;.empty        dbf    d7,.next
  404. ;
  405. ;        move.l    a6,a1
  406. ;        move.l    $4.w,a6
  407. ;        jsr    -414(a6)
  408. ;
  409. ;.nodos
  410. ;        bra.w    .loop
  411. ;
  412. ;        rts
  413.  
  414. ;.tmp_name    dcb.b    34,0
  415.  
  416.         cnop    0,4
  417. max_chip    dc.l 0        ;maximum value for CHIP-RAM
  418. oldlev7        dc.l 0
  419. old_vbr        dc.l 0
  420.  
  421. except_entry
  422.         tst.b    config_RM
  423.         beq.b    .noright
  424.         btst    #10-8,$dff016
  425.         beq.w    monitor
  426. .noright
  427.         tst.b    config_key
  428.         beq.b    .nokey
  429.         cmp.b    #$e5,$bfec01
  430.         beq.w    monitor
  431. .nokey
  432.         movem.l    d0/a0,-(a7)
  433.  
  434.         move.w    8+6(a7),d0
  435.         and.w    #$fff,d0
  436.         move.w    d0,a0
  437.         move.l    (a0),.jmp_addr
  438.  
  439.         movem.l    (a7)+,d0/a0
  440.  
  441.         move.l    .jmp_addr(pc),-(a7)
  442.         rts
  443.  
  444.         cnop 0,4
  445. .jmp_addr    dc.l 0
  446.  
  447.         cnop 0,16
  448.  
  449. location    dc.l 0            ;HRTmon location
  450.         dc.b "HRT!"
  451. new_except    dcb.l    $100,0
  452.  
  453.         dc.b "ATZ!"
  454.         dc.l monitor            ;trap vector
  455.  
  456.         dc.b "HRTmon "
  457.         version
  458.         dc.b " "
  459.         dc.b "by Alain Malek "
  460.         dc.b "(Hornet of Alcatraz) "
  461.  
  462.         cnop 0,4
  463.  
  464. pic_ptr        dc.l $4b0        ;address used for the bitplan of AR
  465. h=9                    ;heights between two lines
  466.  
  467. ;-------------- init. HRTmon when entered for the 1st time ----
  468.  
  469. init_code    movem.l    d0-a6,-(a7)
  470.  
  471.         move.l    #$12345678,d0
  472.         tst.w    Reset_Flag
  473.         bne.b    .init
  474.         cmp.l    inited,d0
  475.         beq.w    .noinit
  476. .init        move.l    d0,inited
  477.  
  478.         bsr    test_CPU
  479.         move.w    d0,proc_type
  480.  
  481.         bsr    init_ascII
  482.  
  483.         jsr    test_drive    ;test which floppy drive is present
  484.  
  485.         tst.b    drive_present+1
  486.         beq.b    .noDF1
  487.         move.l    #floppy1,floppy0    ;add DF1: partition
  488. .noDF1
  489.  
  490.         move.w    proc_type,d0
  491.         add.b    #'0',d0
  492.         move.b    d0,mc_txt+5
  493.  
  494.         jsr    init_fbuffer
  495.  
  496.         tst.b    config_IDE
  497.         beq.b    .noide
  498.  
  499.         move.l    ide_irq,d0
  500.         beq.b    .noIDEirq
  501.         move.l    d0,a3
  502.         tst.b    (a3)
  503.         bpl.b    .noIDEirq
  504.         move.l    ide_base,a3
  505.         tst.b    config_A1200
  506.         bne.b    .go1200
  507.         move.w    ide_status,d0
  508.         move.b    (a3,d0.w),d0
  509.         bra.b    .noIDEirq
  510. .go1200        jsr    wait_irq        ;remove IRQ request from IDE
  511. .noIDEirq
  512.  
  513.         jsr    find_part
  514. .noide
  515.  
  516.         lea.l    custom,a1
  517.         move.w    #$4489,$7e(a1)
  518.         move.w    #$20,$1dc(a1)
  519.         move.w    #$3081,$8e(a1)
  520.         move.w    #$30c1,$90(a1)
  521.         move.w    #$0038,$92(a1)
  522.         move.w    #$00d0,$94(a1)
  523.         move.w    #0,$108(a1)
  524.         move.w    #0,$10a(a1)
  525.         move.w    #0,$106(a1)
  526.         move.w    #0,$1fc(a1)
  527.         move.w    #$9200,$100(a1)
  528.         move.w    #0,$102(a1)
  529.  
  530.  
  531. .noinit        movem.l    (a7)+,d0-a6
  532.         rts
  533.  
  534.  
  535. ;test if exec is here and valid
  536. ;d0=0 ok, -1 = no system
  537.  
  538. exec_here    movem.l    d1/a0-a1,-(a7)
  539.  
  540.         move.l    $4.w,a0
  541.         move.l    a0,d0
  542.         lsr.l    #1,d0
  543.         bcs.b    .nosafe
  544.         lea.l    34(a0),a1
  545.         moveq    #0,d0
  546.         moveq    #$18-1,d1
  547. .add        add.w    (a1)+,d0
  548.         dbf    d1,.add
  549.         not.w    d0
  550.         cmp.w    82(a0),d0
  551.         bne.b    .nosafe
  552.  
  553.         moveq    #0,d0
  554.         bra.b    .ok
  555.  
  556. .nosafe        moveq    #-1,d0
  557. .ok        movem.l    (a7)+,d1/a0-a1
  558.         rts
  559.  
  560.         cnop 0,4
  561.  
  562. ;-------------- when in AR VBR points here ----------------
  563.  
  564. AR_vbr
  565.         dc.l error,error,error,error    ;$00-$0c
  566.         dc.l error,error,error,error    ;$10-$1c
  567.         dc.l error,error,error,error    ;$20-$2c
  568.         dc.l error,error,error,error    ;$30-$3c
  569.         dc.l error,error,error,error    ;$40-$4c
  570.         dc.l error,error,error,error    ;$50-$5c
  571.         dc.l error,error    ;$60,$64
  572.         dc.l newirq2        ;$68        ;keyboard irq
  573.         dc.l newirq        ;$6c        ;VBL irq
  574.         dc.l error        ;$70
  575.         dc.l error        ;$74
  576.         dc.l error        ;$78
  577.         dc.l .onlyret        ;$7c
  578.         dc.l error,error,error,error    ;$80-$8c
  579.         dc.l error,error,error,error    ;$90-$9c
  580.         dc.l error,error,error,error    ;$a0-$ac
  581.         dc.l error,error,error,error    ;$b0-$bc
  582.         dc.l error,error,error,error    ;$c0-$cc
  583.         dc.l error,error,error,error    ;$d0-$dc
  584.         dc.l error,error,error,error    ;$e0-$ec
  585.         dc.l error,error,error,error    ;$f0-$fc
  586.  
  587. .onlyret    rte
  588.  
  589. ;-------------- jmp here if an unexpected exception is raised ----------
  590. ;-------------- (should never happen !) --------------------------------
  591.  
  592. error        move.w    #$2700,sr
  593.         move.l    2(a7),start
  594.         move.w    (a7),start+4
  595.         move.w    6(a7),start+6
  596. .loop        move.w    #0,$dff106
  597.         move.w    $dff006,$dff180        ;flash screen
  598.         bra.b    .loop
  599.  
  600.         cnop 0,4
  601.  
  602. **************************************************************************
  603. ;-------------- Entry point of the Action Replay -------------------------
  604.  
  605. entered        dc.b 0            ;bit 0 set if in HRTmon
  606.         cnop 0,4
  607.  
  608.  
  609. monitor        move.l    a0,-(a7)
  610.         lea.l    entered(pc),a0
  611.         bset    #0,(a0)
  612.         beq.b    .enter
  613.         move.l    (a7)+,a0
  614.         rte                ;don't enter twice
  615.  
  616. .enter
  617.         move.l    (a7)+,a0
  618.         move.w    #$2700,sr
  619.  
  620.         movem.l    d0-a7,registres
  621.  
  622.         lea.l    stack,a7        ;Own stack
  623.                         ;now bsr are allowed
  624.  
  625.         bsr    ClearCache
  626.  
  627.         tst.b    config_lview
  628.         beq.b    .nolview
  629.         bsr    exec_here
  630.         bne.b    .nolview
  631.         move.l    gfxbase(pc),a6
  632.         move.l    34(a6),d0        ;get actual view
  633.         beq.b    .nolview
  634.         move.l    d0,wbview
  635.         sub.l    a1,a1
  636.         jsr    -222(a6)        ;LoadView(NULL)
  637.         move.l    signal_no(pc),d0
  638.         lea.l    tc_block(pc),a1
  639.         move.l    $4.w,a6
  640.         jsr    -324(a6)        ;Signal
  641. .nolview
  642.  
  643.         bsr    init_code
  644.  
  645.         bsr    ClearCache
  646.  
  647.  
  648.         cmp.w    #4,proc_type
  649.         blt.b    .notrans0
  650.     MC68040
  651.         movec    itt0,d0
  652.         move.l    d0,itt0_reg
  653.         movec    itt1,d0
  654.         move.l    d0,itt1_reg
  655.         movec    dtt0,d0
  656.         move.l    d0,dtt0_reg
  657.         movec    dtt1,d0
  658.         move.l    d0,dtt1_reg
  659.         move.l    #$0000a040,d0
  660.         movec    d0,itt0
  661.         movec    d0,dtt0
  662.         moveq    #0,d0
  663.         movec    d0,itt1
  664.         movec    d0,dtt1
  665.         movec    tc,d0
  666.         move.l    d0,tc_reg
  667.         cpusha    bc
  668.         cinva    bc
  669.         dc.w $f518        ;pflusha
  670.     MC68030
  671. .notrans0
  672.  
  673.         lea.l    $dff000,a6
  674.         move.l    $4(a6),OldRaster    ;save raster pos
  675.                         ;(wrong coz of .waittrap !)
  676.  
  677. .blit        btst    #6,($2,a6)
  678.         bne.b    .blit            ;wait end of blitter operation
  679.  
  680.         move.l    a7_reg,a0
  681.         move.w    (a0),sr_reg
  682.         move.l    2(a0),pc_reg
  683.  
  684.         btst    #5,$bfe001        ;need to wait end of DMA disk ?
  685.         bne.b    .no_drive
  686.         move.l    #$20000,d1
  687. .loop        subq.l    #1,d1
  688.         beq.b    .no_drive
  689.         move.w    $1e(a6),d0        ;wait for DMAdisk IRQ
  690.         and.w    #2,d0
  691.         beq.b    .loop
  692. .no_drive
  693.         move.l    USP,a0
  694.         move.l    a0,usp_reg
  695.         move.l    a7_reg,ssp_reg
  696.         move.w    sr_reg,d0
  697.         and.w    #$2000,d0
  698.         bne.b    ok_ssp_a7
  699.         move.l    a0,a7_reg
  700. ok_ssp_a7    movec    VBR,d0
  701.         move.l    d0,vbr_reg
  702.         movec    CACR,d0
  703.         move.l    d0,cacr_reg
  704.         moveq    #0,d0
  705.         cmp.w    #6,proc_type
  706.         bne.b    .no60
  707.         move.l    #'BUSR',CAAR_txt
  708.         dc.w    $4e7a,$0008        ;movec    BUSCR,d0
  709.         bra.b    .nocaar
  710. .no60        cmp.w    #4,proc_type
  711.         bge.b    .nocaar
  712.         movec    CAAR,d0
  713. .nocaar        move.l    d0,caar_reg
  714.         move.l    ssp_reg,isp_reg
  715.         move.l    ssp_reg,d0
  716.         cmp.w    #6,proc_type        ;68060 ?
  717.         beq.b    .nomsp
  718.         movec    MSP,d0
  719.         bra.b    .okmsp
  720. .nomsp        move.l    #'PCR=',MSP_txt
  721.         dc.w    $4e7a,$0808        ;movec    PCR,d0
  722. .okmsp        move.l    d0,msp_reg
  723.  
  724.         cmp.w    #4,proc_type
  725.         bge.b    .no23
  726.         or.w    #$2111,d0        ;switch all CACHE ON
  727.         movec    d0,CACR            ;(68020/68030 only)
  728. .no23
  729.  
  730.         lea.l    (AR_vbr,pc),a0
  731.         movec    a0,VBR            ;init AR vbr
  732.  
  733.         bsr    save_custom
  734.  
  735.         bsr    save_CIA
  736.  
  737.         move.l    #-1,trace_address
  738.  
  739. ;-------------- don't trace subroutine in tracer ? --------
  740.  
  741.         tst.b    trace_bsr
  742.         beq.b    .no_bsr
  743.         tst.w    trace_count
  744.         beq.b    .oky
  745.         clr.w    trace_count
  746.         sf    trace_bsr
  747.         bra.b    .no_bsr
  748. .oky
  749.         move.w    sr_reg,d0
  750.  
  751.         move.l    a7_reg,a0
  752.         and.w    #$2000,d0
  753.         beq.b    .no_super
  754.         addq.l    #6,a0            ;skip SR and PC
  755.  
  756.         move.w    (a0),d0            ;read stack frame no
  757.         lsr.w    #4,d0
  758.         lsr.w    #8,d0
  759.         lea.l    frame(pc),a4
  760.         add.w    (a4,d0.w*2),a0        ;add stack frame size
  761. .no_super    move.l    (a0),tracer_old_rts
  762.         move.l    #.tracer_rts,(a0)
  763.         move.l    vbr_reg,a4
  764.         move.l    #.tracer_ill,$10(a4)
  765.         sf    trace_bsr
  766.         bra.b    .out
  767. .tracer_rts    illegal
  768. .tracer_ill    move.l    tracer_old_rts,2(a7)
  769.         bra.w    monitor
  770.  
  771. .no_bsr
  772. ;-------------------------------------------
  773.  
  774.         bsr    ClearCache
  775.  
  776.         bsr.w    super            ;enter editor
  777.  
  778. .out        move.w    #$7fff,d0
  779.         move.w    d0,$9a(a6)
  780.         move.w    d0,$96(a6)
  781.         move.w    d0,$9c(a6)
  782.  
  783.         bsr    restore_CIA
  784.         bsr    restore_custom
  785.  
  786.         cmp.w    #6,proc_type        ;68060 ?
  787.         beq.w    .nomsp2
  788.         move.l    msp_reg,a0
  789.         movec    a0,MSP
  790.         bra.b    .okmsp2
  791. .nomsp2        move.l    msp_reg,a0
  792.         dc.w    $4e7b,$8808        ;movec    a0,PCR
  793. .okmsp2
  794.         move.l    usp_reg,a0
  795.         move.l    a0,USP
  796.         move.l    ssp_reg,a7
  797.  
  798.         move.w    sr_reg,(a7)
  799.  
  800.         move.l    vbr_reg,a4
  801.  
  802.         tst.w    trace_count
  803.         beq.b    trace_off
  804.         st    no_kill            ;don't kill AR on exit
  805.         or.w    #$8000,(a7)
  806.         move.l    $24(a4),old_trace
  807.         lea.l    trace_reach(pc),a0
  808.         move.l    a0,$24(a4)
  809.  
  810. trace_off    cmp.l    #-1,trace_address
  811.         beq.b    tracea_off
  812.         st    no_kill            ;don't kill AR on exit
  813.         or.w    #$8000,(a7)
  814.         move.l    $24(a4),old_trace
  815.         lea.l    tracea_reach(pc),a0
  816.         move.l    a0,$24(a4)
  817. tracea_off
  818.         move.l    pc_reg,2(a7)
  819.  
  820.         tst.b    debug            ;debug mode on ?
  821.         beq.b    .nodebug
  822.         st    no_kill            ;don't kill AR on exit
  823. .nodebug
  824.         bsr    ClearCache
  825.         cmp.w    #6,proc_type
  826.         bne.b    .no60
  827.         move.l    caar_reg,a0
  828.         dc.w    $4e7b,$8008        ;movec a0,BUSCR
  829. .no60        cmp.w    #4,proc_type
  830.         bge.b    .nocaar2
  831.         move.l    caar_reg,a0
  832.         movec    a0,CAAR
  833. .nocaar2    move.l    cacr_reg,d0
  834.         movec    d0,CACR            ;restore CACR
  835.  
  836.         cmp.w    #4,proc_type
  837.         blt.b    .notrans
  838.     MC68040
  839.         move.l    itt0_reg,d0
  840.         movec    d0,itt0
  841.         move.l    itt1_reg,d0
  842.         movec    d0,itt1
  843.         move.l    dtt0_reg,d0
  844.         movec    d0,dtt0
  845.         move.l    dtt1_reg,d0
  846.         movec    d0,dtt1
  847.         cpusha    bc
  848.         cinva    bc
  849.         dc.w $f518        ;pflusha
  850.     MC68030
  851. .notrans
  852.  
  853.         move.l    custom+$4,d0
  854.         lsr.l    #1,d0
  855.         lsr.w    #7,d0
  856. .raster        move.l    $4(a6),d1        ;wait raster pos
  857.         lsr.l    #1,d1            ;for exit
  858.         lsr.w    #7,d1
  859.         cmp.w    d0,d1
  860. ;        bne.b    .raster
  861.  
  862.         tst.b    reboot
  863.         beq.b    .noreboot
  864.         sf    reboot
  865.         lea.l    $50000,a0
  866.         lea.l    start,a1
  867.         move.w    #$2f000/4-1,d0
  868. .copy        move.l    (a1)+,(a0)+        ;copy HRTmon to $50000
  869.         dbf    d0,.copy
  870.  
  871. .noreboot    tst.b    kill
  872.         beq.b    .nokill
  873.  
  874.         move.l    old_vbr(pc),a0
  875.         movec    a0,VBR
  876.         bra.b    .okkill
  877.  
  878. .nokill        move.l    vbr_reg,a0
  879.         movec    a0,VBR
  880.  
  881. .okkill        movem.l    registres,d0-d7/a0-a6
  882.         sf    entered
  883.  
  884.         rte
  885.  
  886. *************************************************************
  887. ;Clear instruction and data cache of 68020,68030,68040,68060
  888.  
  889. ClearCache    move.l    d0,-(a7)
  890.         cmp.w    #4,proc_type
  891.         bge.b    .cic_040
  892.  
  893.         movec    CACR,d0
  894.         cmp.w    #3,proc_type
  895.         bne.b    .no30
  896.         or.w    #$0800,d0
  897. .no30        or.w    #$8,d0
  898.         movec    d0,CACR
  899.         bra.b    .end
  900. .cic_040
  901.     MC68040
  902.         cpusha    BC
  903.         cinva    BC
  904.     MC68030
  905. .end
  906.         move.l    (a7)+,d0
  907.         rts
  908.  
  909. ***********************************************************
  910. ;test if 68020,30,40,or 60 processor
  911.  
  912. ;<- d0=processor type 2=68020,3=68030,4=68040,6=68060
  913.  
  914.  
  915. test_CPU    move.w    #$2700,sr
  916.         movem.l    d1-d2/a0/a4,-(a7)
  917.         movec    VBR,a0
  918.         move.l    a0,.old_vbr
  919.  
  920.         lea.l    .except,a0
  921.         movec    a0,VBR
  922.  
  923.         move.l    a7,a4
  924.  
  925.         moveq    #1,d0
  926.         moveq    #1,d1
  927.         moveq    #1,d2
  928.         move.l    #.mc60,($f4,a0)    ;new unimplemented instr.
  929.         muls.l    d0,d1:d2    ;68060 ? (not implemented on 060)
  930.  
  931.     MC68040
  932.         move.l    #.mc23,($10,a0)    ;new illegal
  933.         movec    URP,d0        ;68040 and 68060 only
  934.     MC68030
  935.  
  936.         moveq    #4,d0
  937.         bra.b    .out
  938.  
  939. .ret23        move.l    #.mc20,($2c,a0)    ;new F-line
  940.         pflusha            ;030 MMU instruction
  941.  
  942.         moveq    #3,d0
  943.  
  944. .out        move.l    a4,a7
  945.         move.l    .old_vbr,a0
  946.         movec    a0,VBR
  947.         movem.l    (a7)+,d1-d2/a0/a4
  948.         move.w    #$2700,sr
  949.         rts
  950.  
  951. .mc60        moveq    #6,d0
  952.         move.l    #.out,(2,a7)
  953.         rte
  954.  
  955. .mc23        move.l    #.ret23,(2,a7)
  956.         rte
  957.  
  958. .mc20        moveq    #2,d0
  959.         move.l    #.out,(2,a7)
  960.         rte
  961.  
  962. .old_vbr    dc.l 0
  963. .kill        rte
  964.         cnop 0,4
  965. .except        dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  966.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  967.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  968.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  969.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  970.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  971.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  972.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  973.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  974.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  975.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  976.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  977.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  978.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  979.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  980.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  981.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  982.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  983.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  984.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  985.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  986.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  987.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  988.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  989.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  990.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  991.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  992.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  993.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  994.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  995.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  996.         dc.l .kill,.kill,.kill,.kill,.kill,.kill,.kill,.kill
  997.  
  998. ***********************************************************
  999. ;-------------- save custom registers ---------------------
  1000. ;-------------- palette saving done by read_palette -------
  1001.  
  1002. save_custom    movem.l    d0/a0-a4,-(a7)
  1003.  
  1004. ;        lea.l    Action_CUST,a0
  1005.         lea.l    custom,a1
  1006.         move.l    a1,a4
  1007. ;        move.w    #$200/8-1,d0
  1008. ;.copy        move.l    (a0)+,(a1)+
  1009. ;        move.l    (a0)+,(a1)+
  1010. ;        dbf    d0,.copy
  1011.  
  1012.         move.w    $2(a6),d0
  1013.         move.w    d0,2(a4)
  1014.         or.w    #$8000,d0
  1015.         move.w    d0,$96(a4)    ;DMACON
  1016.         move.w    #$7fff,$96(a6)
  1017.         move.w    $1c(a6),d0
  1018.         move.w    d0,$1c(a4)
  1019.         or.w    #$8000,d0
  1020.         move.w    d0,$9a(a4)    ;INTENA
  1021.         move.w    #$7fff,$9a(a6)
  1022.         move.w    $1e(a6),d0
  1023.         move.w    d0,$1e(a4)
  1024.         or.w    #$8000,d0
  1025.         move.w    d0,$9c(a4)    ;INTREQ
  1026.         move.w    #$7fff,$9c(a6)
  1027.  
  1028.         tst.b    config_A1200
  1029.         beq.b    .noa1200
  1030.         move.b    $daa000,pcmcia_intena
  1031.         move.b    #0,$daa000    ;disable pcmcia interrupts
  1032.         move.b    $da9000,d0
  1033.         eor.b    #$2c,d0
  1034.         and.b    #$c0,d0
  1035.         move.b    d0,$da9000    ;ack pending interrupts
  1036. .noa1200
  1037.         move.w    $10(a6),d0
  1038.         move.w    d0,$10(a4)
  1039.         or.w    #$8000,d0
  1040.         move.w    d0,$9e(a4)    ;ADKCON
  1041.  
  1042.         move.l    OldRaster,$4(a4)    ;VPOSR,VHPOSR
  1043.  
  1044.         lea.l    $a(a6),a0
  1045.         lea.l    $a(a4),a1
  1046.         moveq    #9-1,d0
  1047. .copy1        move.w    (a0)+,(a1)+
  1048.         dbf    d0,.copy1
  1049.  
  1050.         move.w    $7c(a6),$7c(a4)        ;LISAID
  1051.         move.w    $1da(a6),$1da(a4)    ;HHPOSR
  1052.  
  1053.     ;    moveq    #0,d0
  1054.     ;    jsr    analyse_copper
  1055.  
  1056.         movem.l    (a7)+,d0/a0-a4
  1057.         rts
  1058.  
  1059. ;-------------- restore custom registers ------------------
  1060.  
  1061. restore_custom    movem.l    d0/a1,-(a7)
  1062.         lea.l    custom,a1
  1063.  
  1064.         ;move.l    $20(a1),$20(a6)        ;DISKPTR
  1065.         move.w    $7e(a1),$7e(a6)        ;DSKSYNC
  1066.         move.w    $9e(a1),$9e(a6)        ;ADKCON
  1067.         ;move.w    $34(a1),$34(a6)        ;POTGO
  1068.         move.w    $1dc(a1),$1dc(a6)    ;BEAMCON0
  1069.         ;move.w    $1e4(a1),$1e4(a6)    ;DIWHIGH
  1070.         move.l    $8e(a1),$8e(a6)        ;diwstrt/stop
  1071.         move.l    $92(a1),$92(a6)        ;ddfstrt/stop
  1072.         ;move.l    $e0(a1),$e0(a6)        ;BPL1PT
  1073.         move.w    $1fc(a1),$1fc(a6)    ;FMODE
  1074.         move.l    $108(a1),$108(a6)    ;BPL1MOD
  1075.         move.w    $106(a1),$106(a6)    ;BPLCON3
  1076.         move.l    $100(a1),$100(a6)    ;BPLCON0
  1077.         ;move.w    $10c(a1),$10c(a6)    ;BPLCON4
  1078.  
  1079.         move.w    $96(a1),$96(a6)        ;DMACON
  1080.         move.w    $9c(a1),$9c(a6)        ;INTREQ
  1081.         move.w    $9a(a1),$9a(a6)        ;INTENA
  1082.  
  1083.         tst.b    config_A1200
  1084.         beq.b    .noa1200
  1085.         move.b    pcmcia_intena,$daa000
  1086. .noa1200
  1087.  
  1088. ;        move.l    $84(a1),d0        ;correct
  1089. ;        cmp.l    #$f28,d0        ;an AmigaOS
  1090. ;        bne.b    .nof28            ;problem
  1091. ;        tst.l    $f28.w            ;of the LoadView(NULL)
  1092. ;        bne.b    .nof28
  1093. ;        move.l    #$f24,$84(a1)
  1094. ;        move.l    #$f24,$84(a6)
  1095. ;.nof28
  1096.         movem.l    (a7)+,d0/a1
  1097.         rts
  1098.  
  1099. save_CIA    movem.l    a0-a1,-(a7)
  1100.  
  1101. ;        lea.l    Action_CIAA,a0
  1102. ;        lea.l    CIAA,a1
  1103. ;        move.b    $1(a0),(a1)+
  1104. ;        move.b    $101(a0),(a1)+
  1105. ;        move.b    $201(a0),(a1)+
  1106. ;        move.b    $301(a0),(a1)+
  1107. ;        move.b    $401(a0),(a1)+
  1108. ;        move.b    $501(a0),(a1)+
  1109. ;        move.b    $601(a0),(a1)+
  1110. ;        move.b    $701(a0),(a1)+
  1111. ;        move.b    $801(a0),(a1)+
  1112. ;        move.b    $901(a0),(a1)+
  1113. ;        move.b    $a01(a0),(a1)+
  1114. ;        move.b    $b01(a0),(a1)+
  1115. ;        move.b    $c01(a0),(a1)+
  1116. ;        move.b    $d01(a0),(a1)+
  1117. ;        move.b    $e01(a0),(a1)+
  1118. ;        move.b    $f01(a0),(a1)+
  1119. ;
  1120. ;        lea.l    Action_CIAB,a0
  1121. ;        lea.l    CIAB,a1
  1122. ;        move.b    (a0),(a1)+
  1123. ;        move.b    $100(a0),(a1)+
  1124. ;        move.b    $200(a0),(a1)+
  1125. ;        move.b    $300(a0),(a1)+
  1126. ;        move.b    $400(a0),(a1)+
  1127. ;        move.b    $500(a0),(a1)+
  1128. ;        move.b    $600(a0),(a1)+
  1129. ;        move.b    $700(a0),(a1)+
  1130. ;        move.b    $800(a0),(a1)+
  1131. ;        move.b    $900(a0),(a1)+
  1132. ;        move.b    $a00(a0),(a1)+
  1133. ;        move.b    $b00(a0),(a1)+
  1134. ;        move.b    $c00(a0),(a1)+
  1135. ;        move.b    $d00(a0),(a1)+
  1136. ;        move.b    $e00(a0),(a1)+
  1137. ;        move.b    $f00(a0),(a1)+
  1138.  
  1139.         move.b    #$c0,$bfd200        ;reinit CIAs
  1140.         move.b    #$ff,$bfd300        ;for
  1141.         move.b    #$03,$bfe201        ;AR
  1142. ;        move.b    #$7f,$bfec01
  1143.         move.b    #$00,$bfee01
  1144.         move.b    #$88,$bfed01
  1145.         move.b    #$ff,$bfd100
  1146.         sf    mot_on
  1147.  
  1148.         move.w #$0f00,$34(a6)        ;reinit right-mouse button
  1149.  
  1150.         movem.l    (a7)+,a0-a1
  1151.         rts
  1152.  
  1153. restore_CIA    movem.l    a0-a1,-(a7)
  1154.  
  1155. ;        lea.l    $bfe000,a0
  1156. ;        lea.l    CIAA,a1
  1157. ;        clr.b    $e01(a0)
  1158. ;        clr.b    $f01(a0)
  1159. ;        move.b    (a1),$1(a0)
  1160. ;        move.b    1(a1),$101(a0)
  1161. ;        move.b    2(a1),$201(a0)
  1162. ;        move.b    3(a1),$301(a0)
  1163. ;        move.b    4(a1),$401(a0)
  1164. ;        move.b    5(a1),$501(a0)
  1165. ;        move.b    6(a1),$601(a0)
  1166. ;        move.b    7(a1),$701(a0)
  1167. ;        move.b    8(a1),$801(a0)
  1168. ;        move.b    9(a1),$901(a0)
  1169. ;        move.b    10(a1),$a01(a0)
  1170. ;        move.b    11(a1),$b01(a0)
  1171. ;        move.b    12(a1),$c01(a0)
  1172. ;        move.b    14(a1),$e01(a0)
  1173. ;        move.b    15(a1),$f01(a0)
  1174. ;        move.b    13(a1),$d01(a0)
  1175. ;
  1176. ;        lea.l    $bfd000,a0
  1177. ;        lea.l    CIAB,a1
  1178. ;        clr.b    $e00(a0)
  1179. ;        clr.b    $f00(a0)
  1180. ;        move.b    (a1),(a0)
  1181. ;        move.b    1(a1),$100(a0)
  1182. ;        move.b    2(a1),$200(a0)
  1183. ;        move.b    3(a1),$300(a0)
  1184. ;        move.b    4(a1),$400(a0)
  1185. ;        move.b    5(a1),$500(a0)
  1186. ;        move.b    6(a1),$600(a0)
  1187. ;        move.b    7(a1),$700(a0)
  1188. ;        move.b    8(a1),$800(a0)
  1189. ;        move.b    9(a1),$900(a0)
  1190. ;        move.b    10(a1),$a00(a0)
  1191. ;        move.b    11(a1),$b00(a0)
  1192. ;        move.b    12(a1),$c00(a0)
  1193. ;        move.b    14(a1),$e00(a0)
  1194. ;        move.b    15(a1),$f00(a0)
  1195. ;        move.b    13(a1),$d00(a0)
  1196.  
  1197.         movem.l    (a7)+,a0-a1
  1198.         rts
  1199.  
  1200. ***********************************************************
  1201. ; update status line (at bottom of screen)
  1202.  
  1203. print_status:    movem.l    d0-d3/a0,-(a7)
  1204.         lea.l    insert_off_txt,a0
  1205.         tst.b    insert_mode
  1206.         beq.b    .ok_ins_off
  1207.         lea.l    insert_on_txt,a0
  1208. .ok_ins_off    moveq    #76,d0
  1209.         move.w    screen_height,d1
  1210.         subq.w    #1,d1
  1211.         moveq    #3-1,d3
  1212. .loop        move.b    (a0)+,d2
  1213.         bsr    print_char2
  1214.         addq.w    #1,d0
  1215.         dbf    d3,.loop
  1216.  
  1217.         lea.l    start(pc),a0
  1218.         move.l    a0,d0
  1219.         lea.l    watch_txt,a0
  1220.         moveq    #8,d1
  1221.         bsr    conv_hex
  1222.         move.w    screen_height,d1
  1223.         subq.w    #1,d1
  1224.         moveq    #47,d0
  1225.         moveq    #8-1,d3
  1226. .loop2        move.b    (a0)+,d2
  1227.         bsr    print_char2
  1228.         addq.w    #1,d0
  1229.         dbf    d3,.loop2
  1230.  
  1231.         movem.l    (a7)+,d0-d3/a0
  1232.         rts
  1233.  
  1234. ***********************************************************
  1235.  
  1236. super        move.w    #$2000,sr        ;enable interrupts
  1237.  
  1238.         cmp.b    #1,config_screen
  1239.         bne.b    .nontsc
  1240.         move.w    #0,$1dc(a6)        ;NTSC mode 15Khz
  1241.         bra.b    .okscreen
  1242. .nontsc        move.w    #$20,$1dc(a6)        ;PAL mode 15Khz
  1243. .okscreen
  1244.         jsr    read_palette
  1245.  
  1246.         bsr    clear_break
  1247.  
  1248.         sf    no_kill            ;kill AR on exit
  1249.  
  1250.         move.l    vbr_reg,a4
  1251.         move.l    illegal_except,d0    ;restore vector used
  1252.         beq.b    no_illegal_init        ;by breakpoint
  1253.         move.l    d0,$10(a4)
  1254. no_illegal_init
  1255.  
  1256.         bsr    set_pic        ;init display area
  1257.  
  1258.         moveq    #0,d0
  1259.         lea.l    $140(a6),a0
  1260.         moveq    #$16-1,d1
  1261. clr_spr        move.l    d0,(a0)+        ;clear sprites data
  1262.         dbf    d1,clr_spr
  1263.  
  1264.         bsr    print_page
  1265.  
  1266.         tst.b    trace_moni        ;in tracer ?
  1267.         bne.b    no_print_trace
  1268.  
  1269.         bsr    check_debug        ;print debug entry message
  1270.  
  1271.         tst.b    BP_reach        ;entered from BreakPoint ?
  1272.         beq.b    no_BP_enter
  1273.         move.l    Break_Address,d0
  1274.         moveq    #8,d1
  1275.         lea.l    BP_enter_txt,a0
  1276.         bsr    print_curs
  1277.         bsr    print_hexCR
  1278. no_BP_enter
  1279.         tst.b    BPJ_reach        ;entered from JSR BP ?
  1280.         beq.b    no_BPJ_enter
  1281.         move.l    Break_Address,d0
  1282.         moveq    #8,d1
  1283.         lea.l    BPJ_enter_txt,a0
  1284.         bsr    print_curs
  1285.         bsr    print_hexCR
  1286. no_BPJ_enter
  1287.         bsr    clear_cursor
  1288.         clr.w    cursor_x
  1289.         bsr    print_reg        ;print CPU registers
  1290.         move.l    pc_reg,dis_ptr
  1291.         bsr    single_inst        ;disassemble 1 instr. at PC
  1292.  
  1293. no_print_trace
  1294.         sf    escape
  1295.  
  1296.         tst.b    BPatPC
  1297.         beq.b    .noPC
  1298.         st    escape
  1299. .noPC
  1300.         sf    p_used            ;clr signal to allow sp command
  1301.         bsr    force_change        ;force floppy disk change
  1302.  
  1303. ;.joy        move.w    #0,$dff106
  1304. ;        move.w    #$f,$dff180
  1305. ;        btst    #7,$bfe001
  1306. ;        bne.b    .joy
  1307.  
  1308. .raster        move.l    $4(a6),d0
  1309.         lsr.l    #1,d0
  1310.         lsr.w    #7,d0
  1311.         cmp.w    #$f0,d0
  1312.         blt.b    .raster
  1313.  
  1314.         move.b    #$7f,key_prev
  1315.  
  1316.         tst.b    config_IDE
  1317.         beq.b    .noIDEirq
  1318.         move.l    ide_irq(pc),d0
  1319.         beq.b    .noIDEirq
  1320.         move.l    d0,a3
  1321.         tst.b    (a3)
  1322.         bpl.b    .noIDEirq
  1323.         move.l    ide_base(pc),a3
  1324.         jsr    wait_irq        ;remove IRQ request from IDE
  1325. .noIDEirq
  1326.         bsr    print_status
  1327.  
  1328.         move.w    #$7fff,$9c(a6)        ;disable all INTREQ
  1329.         move.w    #$8300,$96(a6)        ;bitplan DMA on
  1330.         move.w    #$c028,$9a(a6)        ;VBL+CIAA IRQ on
  1331.  
  1332.         moveq    #2-1,d0
  1333. .loopk        sf    VBL
  1334. .waitk        tst.b    VBL            ;wait to flush keyboard
  1335.         beq.b    .waitk            ;buffer
  1336.         dbf    d0,.loopk
  1337.  
  1338.         clr.w    nb_keys
  1339.  
  1340. ;-------------- Main Loop ---------------------------------
  1341.  
  1342. wait        tst.w    nb_keys
  1343.         bne.b    .go_fast
  1344.         stop    #$2000
  1345.  
  1346. .go_fast
  1347.  
  1348. ;-------------- handle repeat key --------------------
  1349.  
  1350.         move.w    #$2700,sr
  1351.         move.b    key_prev,d0
  1352.         move.w    nb_keys,d1        ;key in buffer ?
  1353.         beq.b    .no_key
  1354.         subq.w    #1,nb_keys
  1355.         subq.w    #1,d1
  1356.         lea.l    key_buffer,a0
  1357.         move.b    (a0),d0
  1358. .copy        move.b    1(a0),(a0)+        ;remove one key from buffer
  1359.         dbf    d1,.copy
  1360. .no_key        move.w    #$2000,sr
  1361.  
  1362.         move.b    d0,d1
  1363.         cmp.b    key_prev,d0
  1364.         beq.b    same_key
  1365.         moveq    #0,d2
  1366.         move.b    config_delay,d2
  1367.         move.w    d2,time_repeat
  1368.         bra.b    ok_same_key
  1369. same_key
  1370.         tst.w    time_repeat
  1371.         bmi.w    ok_same_key
  1372.         move.b    #$7f,d0
  1373.  
  1374. ok_same_key    move.b    d1,key_prev
  1375.         move.b    d0,key
  1376.  
  1377. ;-------------- main stuff ---------------------------
  1378.  
  1379.         bsr    special_keys
  1380.  
  1381.         tst.b    trace_moni    ;tracer on ?
  1382.         beq.b    .go_key
  1383.         bsr.w    do_tracer
  1384.         bra.b    .no_key
  1385.  
  1386. .go_key        bsr    normal_keys
  1387.  
  1388. .no_key        tst.b    escape        ;quit AR ?
  1389.         beq.w    wait
  1390.  
  1391. ;-------------- exit ---------------------------------
  1392.  
  1393. out_mon        st    tracer_refresh
  1394.         move.w    #$2700,sr
  1395.         move.w    #$7fff,$9a(a6)
  1396.         move.w    #$7fff,$96(a6)
  1397.         move.w    #$7fff,$9c(a6)
  1398.  
  1399.         tst.b    trace_moni
  1400.         bne.b    .noclr
  1401.         bsr    clear_cursor
  1402. .noclr
  1403.         bsr    remove_pic
  1404.  
  1405.         jsr    restore_palette
  1406.  
  1407.         bsr    init_break        ;set breakpoints
  1408.  
  1409.         move.w    drive,-(a7)
  1410.         moveq    #3,d4            ;first drive SEL (drive0)
  1411.         lea.l    drive_present,a3
  1412.         moveq    #4-1,d5            ;4 drives
  1413. .loopd        tst.b    (a3)+
  1414.         beq.b    .nodrive
  1415.         move.w    d4,drive        ;restore
  1416.         bsr    rest_head        ;floppy drive head pos
  1417. .nodrive    addq.w    #1,d4
  1418.         dbf    d5,.loopd
  1419.         move.w    (a7)+,drive
  1420.  
  1421.         rts
  1422.  
  1423. *******************************************************
  1424. ;------------------------------------------------
  1425. ;-------------- get a key from keyboard ---------
  1426. ;-------------- used for confirmation y/n -------
  1427.  
  1428. ;<- d0=key (ascII)
  1429.  
  1430. get_key        clr.w    nb_keys
  1431. .wait        tst.w    nb_keys
  1432.         beq.b    .wait
  1433.         tst.b    key_buffer    ;key released ?
  1434.         bmi.b    get_key
  1435.         move.w    #$2700,sr
  1436.         clr.w    nb_keys
  1437.         moveq    #0,d0
  1438.         move.b    key_buffer,d0
  1439.         move.b    #$7f,key_prev
  1440.         move.w    #$2000,sr
  1441.         move.l    a0,-(a7)
  1442.         move.l    board_ptr,a0
  1443.         move.b    (a0,d0.w),d0
  1444.         move.l    (a7)+,a0
  1445.         rts
  1446.  
  1447. *******************************************************
  1448. ;-------------- Tracer --------------------------------
  1449.  
  1450. do_tracer    movem.l    d0-d7/a0-a6,-(a7)
  1451.  
  1452.         tst.b    tracer_refresh
  1453.         beq.w    .no_ref
  1454.         sf    tracer_refresh
  1455.         clr.l    cursor_x
  1456.         bsr    print_reg
  1457.  
  1458.         lea.l    empty_txt,a0
  1459.         bsr    print
  1460.  
  1461.         lea.l    tracer_addr,a3
  1462.         move.l    pc_reg,a4
  1463.  
  1464.         moveq    #5,d6            ;no of actual line
  1465.         move.w    screen_height,d0
  1466.         sub.w    #11,d0
  1467. .seek        cmp.l    (a3)+,a4
  1468.         beq.b    .found
  1469.         addq.l    #1,d6
  1470.         dbf    d0,.seek
  1471.  
  1472.         moveq    #5,d6
  1473.         lea.l    tracer_addr,a3
  1474.  
  1475.         move.w    screen_height,d7
  1476.         sub.w    #11,d7
  1477. .loop        move.l    a4,(a3)+
  1478.         move.l    a4,-(a7)
  1479.         bsr    corr_addr
  1480.         lea.l    general_txt,a0
  1481.         moveq    #7,d0        ;upper case, d $address,indir. address
  1482.         jsr    disassemble
  1483.         move.l    (a7)+,a4
  1484.         add.w    d0,a4
  1485.         lea.l    general_txt,a0
  1486.         bsr    print
  1487.         dbf    d7,.loop
  1488.  
  1489. .found
  1490.     movem.w    d0-d1,-(a7)
  1491.     movem.w    actual_pos,d0-d1
  1492.     tst.w    d0
  1493.     bmi.b    .no
  1494.     move.b    #' ',d2
  1495.     bsr    print_char        ;clear old '>'
  1496. .no    movem.w    (a7)+,d0-d1
  1497.  
  1498.         moveq    #11,d0
  1499.         move.l    d6,d1
  1500.         movem.w    d0-d1,actual_pos
  1501.         move.b    #'>',d2
  1502.         bsr    print_char
  1503.  
  1504. .no_ref
  1505.         lea.l    key,a0
  1506.         cmp.b    #$7f,d0
  1507.         beq.w    .nok
  1508.         cmp.b    #$4e,d0
  1509.         bne.b    .nor
  1510.         move.b    #$7f,(a0)
  1511.         move.w    #1,trace_count
  1512.         st    escape
  1513.         st    tracer_refresh
  1514. .nor        cmp.b    #$4d,d0
  1515.         bne.b    .nodown
  1516.         move.b    #$7f,(a0)
  1517.         movem.w    actual_pos,d0-d1
  1518.         move.l    ascII_ptr,a1
  1519.         mulu    #80,d1
  1520.         add.l    d1,a1
  1521.         cmp.b    #'J',1(a1,d0.w)
  1522.         bne.b    .no_jsr
  1523.         cmp.b    #'S',2(a1,d0.w)
  1524.         bne.b    .no_jsr
  1525.         cmp.b    #'R',3(a1,d0.w)
  1526.         beq.b    .go_bsr
  1527.  
  1528. .no_jsr
  1529.         cmp.b    #'B',1(a1,d0.w)
  1530.         bne.b    .no_bsr
  1531.         cmp.b    #'S',2(a1,d0.w)
  1532.         bne.b    .no_bsr
  1533.         cmp.b    #'R',3(a1,d0.w)
  1534.         bne.b    .no_bsr
  1535.  
  1536. .go_bsr        st    trace_bsr
  1537. .no_bsr        move.w    #1,trace_count
  1538.         st    escape
  1539.         st    tracer_refresh
  1540.  
  1541. .nodown
  1542. .nok
  1543.         movem.l    (a7)+,d0-d7/a0-a6
  1544.         rts
  1545.  
  1546. empty_txt    dcb.b 79," "
  1547.         dc.b $a,0
  1548.         even
  1549.  
  1550. *******************************************************
  1551. ;-------------- restore low-mem area used by display --
  1552.  
  1553. remove_pic    tst.b    pic_status
  1554.         beq.b    .okpic
  1555.         sf    pic_status
  1556.         move.w    #$2700,sr
  1557.         st    no_print
  1558.         movem.l    d0/a0-a1,-(a7)
  1559.         moveq    #0,d0
  1560.         move.w    d0,$dff106
  1561.         move.l    d0,$dff180
  1562.         lea.l    $0.w,a0
  1563.         lea.l    backup_pic,a1
  1564.         move.w    #LOSIZE/4-1,d0
  1565. .copy        move.l    (a1)+,(a0)+
  1566.         dbf    d0,.copy
  1567.         movem.l    (a7)+,d0/a0-a1
  1568. .okpic        rts
  1569.  
  1570. ;-------------- save low-mem area and print pic -------
  1571.  
  1572. set_pic        tst.b    pic_status
  1573.         bne.b    .okpic
  1574.         st    pic_status
  1575.         movem.l    d0/a0-a1,-(a7)
  1576.         lea.l    $0.w,a0
  1577.         lea.l    backup_pic,a1
  1578.         move.w    #LOSIZE/4-1,d0
  1579. .copy        move.l    (a0)+,(a1)+
  1580.         dbf    d0,.copy
  1581.         movem.l    (a7)+,d0/a0-a1
  1582.         sf    no_print
  1583.         bsr    print_page
  1584.         move.w    #$2000,sr
  1585. .okpic        rts
  1586.  
  1587. ***********************************************************
  1588. ;-------------- jmp here when a keyboard reset-warn code --
  1589. ;-------------- has been received -------------------------
  1590.  
  1591. go_reset    move.w    #$2700,sr
  1592.         clr.l    inited
  1593.         sf    entered
  1594.         move.l    $f80004,a0
  1595.         subq.l    #2,a0
  1596.         move.w    #0,$dff100
  1597.         move.w    #0,$dff1dc
  1598.         jmp    (a0)
  1599.  
  1600. ***********************************************************
  1601. ;-------------- VBL interrupt handler ---------------------
  1602.  
  1603. newirq        movem.l    d0-d7/a0-a6,-(a7)
  1604.         lea.l    $dff000,a6
  1605.  
  1606.         st    VBL        ;signal a VBL
  1607.  
  1608. ;-------------- init display registers ----------
  1609.         move.l    pic_ptr(pc),d0
  1610.  
  1611.         cmp.b    #1,config_screen
  1612.         bne.b    .nontsc
  1613.  
  1614.         move.l    #$90010000,$100(a6)
  1615.         move.l    #$3081f7c1,$8e(a6)
  1616.         move.w    #$0,$1dc(a6)
  1617.  
  1618.         tst.b    small_pic
  1619.         beq.b    .gofull
  1620.         add.l    #(22-3)*80*h,d0
  1621.         move.l    #$dc81f7c1,$8e(a6)
  1622. ;        move.w    #$2101,$1e4(a6)
  1623. .gofull        move.l    d0,$e0(a6)
  1624.         move.w    #$0c00,$106(a6)
  1625.         move.w    #$0000,$10c(a6)
  1626.         move.l    #$eee,$180(a6)
  1627.         move.l    #$003c00d4,$92(a6)
  1628.         move.w    #0,$108(a6)
  1629.  
  1630.         move.w    #0,$1fc(a6)
  1631.  
  1632.         bra.w    .okmode
  1633.  
  1634.  
  1635. .nontsc        cmp.b    #2,config_screen
  1636.         bne.w    .nomulti
  1637.  
  1638.         tst.b    small_pic
  1639.         beq.b    .gofull2
  1640.         add.l    #(52-3)*80*h,d0
  1641. .gofull2    move.l    d0,$e0(a6)
  1642.  
  1643.         move.l    #$2c4500e5,$8e(a6)
  1644.         move.l    #$00200068,$92(a6)
  1645.         move.w    #$1b88,$1dc(a6)
  1646.         move.w    #$1241,$100(a6)
  1647.         move.w    #0,$108(a6)
  1648.         move.w    #-80,$10a(a6)
  1649.  
  1650.         move.w    #$0000,$1fc(a6)
  1651.  
  1652.         move.w #$0071,$1c0(a6)
  1653.         move.w #$0008,$1c4(a6)
  1654.         move.w #$000e,$1de(a6)
  1655.         move.w #$001c,$1c2(a6)
  1656.         move.w #$001e,$1c6(a6)
  1657.         move.w #$0046,$1e2(a6)
  1658.         move.w #$020c,$1c8(a6)
  1659.         move.w #$0000,$1cc(a6)
  1660.         move.w #$0003,$1e0(a6)
  1661.         move.w #$0200,$1e4(a6)
  1662.         move.w #$0005,$1ca(a6)
  1663.         move.w #$001d,$1ce(a6)
  1664.         move.w #$0012,$104(a6)
  1665.         move.w #$0c21,$106(a6)
  1666.  
  1667.         move.l    #$eee,$180(a6)
  1668.  
  1669.         bra.b    .okmode
  1670.  
  1671. .nomulti
  1672.         move.l    #$90010000,$100(a6)
  1673.         move.l    #$30812cc1,$8e(a6)
  1674.         move.w    #$20,$1dc(a6)
  1675.         tst.b    small_pic
  1676.         beq.b    .gofull3
  1677.         add.l    #(28-3)*80*h,d0
  1678.         move.l    #$11812cc1,$8e(a6)
  1679.         move.w    #$2101,$1e4(a6)
  1680. .gofull3    move.l    d0,$e0(a6)
  1681.         move.w    #$0c00,$106(a6)
  1682.         move.w    #$0000,$10c(a6)
  1683.         move.l    #$eee,$180(a6)
  1684.         move.l    #$003c00d4,$92(a6)
  1685.         move.w    #0,$108(a6)
  1686.  
  1687.         move.w    #0,$1fc(a6)
  1688.  
  1689. .okmode
  1690.  
  1691.  
  1692.         tst.b    trace_moni        ;test if in Tracer
  1693.         bne.b    .no_cur
  1694.         bsr    do_cursor
  1695. .no_cur
  1696.         tst.w    time_repeat
  1697.         bmi.b    no_sub_repeat
  1698.         subq.w    #1,time_repeat        ;for repeat key
  1699. no_sub_repeat
  1700.         bsr    do_watch
  1701.  
  1702.         move.w    #$20,$9c(a6)        ;interrupt ACK
  1703.         movem.l    (a7)+,d0-d7/a0-a6
  1704.         rte
  1705.  
  1706. ; IRQ handler of CIA-A (keyboard)
  1707.  
  1708. newirq2        movem.l    d0-d1/a0/a1/a5-a6,-(a7)
  1709.         lea.l    $dff000,a6
  1710.  
  1711.         tst.b    config_IDE
  1712.         beq.b    .noide
  1713.         move.l    ide_irq(pc),d0
  1714.         beq.b    .noide
  1715.         move.l    d0,a0
  1716.         move.b    (a0),d0            ;interrupt from IDE ?
  1717.         bpl.b    .noide
  1718.         tst.b    config_A1200
  1719.         bne.b    .go1200
  1720.         move.l    ide_base(pc),a1
  1721.         move.w    ide_status,d0
  1722.         move.b    (a1,d0.w),d0
  1723.         st    IDE_IRQ
  1724.         bra.b    .noide
  1725. .go1200        move.w    SR,-(a7)
  1726.         move.w    #$2700,sr
  1727.         move.l    ide_base(pc),a1
  1728.         move.w    ide_status,d0
  1729.         move.b    (a1,d0.w),d0
  1730.         move.b    (a0),d0
  1731.         andi.b    #3,d0
  1732.         or.b    #$7c,d0
  1733.         move.b    d0,(a0)
  1734.         st    IDE_IRQ
  1735.         move.w    (a7)+,SR
  1736. .noide
  1737.  
  1738.         move.b    $bfed01,d0
  1739.         btst    #3,d0        ;test if interrupt from keyboard
  1740.         beq.b    .pas_key
  1741.         move.b    $bfec01,d0    ;get key
  1742.         not.b    d0
  1743.         ror.b    #1,d0
  1744.  
  1745.         cmp.b    #$78,d0
  1746.         beq.w    go_reset
  1747.  
  1748.         cmp.b    #$45,d0
  1749.         bne.b    .no_break
  1750.         st    break
  1751. .no_break
  1752.         tst.b    new_key    ;test if waiting for key-pressed
  1753.         bne.b    .no_buf
  1754.  
  1755.         cmp.w    #64-1,nb_keys
  1756.         beq.b    .pas_key
  1757.  
  1758.         lea.l    key_buffer,a0
  1759.         move.w    nb_keys,d1
  1760.         move.b    d0,(a0,d1.w)        ;save key in key buffer
  1761.         addq.w    #1,nb_keys
  1762. .no_buf        btst    #7,d0
  1763.         bne.b    .nonew
  1764.         sf    new_key
  1765. .nonew        bset    #6,$bfee01
  1766.         moveq    #3-1,d1
  1767. .wait        move.b    6(a6),d0        ;wait 3 raster lines
  1768. .ras        cmp.b    6(a6),d0
  1769.         beq.b    .ras
  1770.         dbf    d1,.wait
  1771.         bclr    #6,$bfee01
  1772. .pas_key    move.w    #$8,$9c(a6)        ;interrupt ACK
  1773.         movem.l    (a7)+,d0-d1/a0/a1/a5-a6
  1774.         rte
  1775.  
  1776.  
  1777. ********************************************************************
  1778. ;------------- Display the actual address of a search process ------
  1779. ;------------- at the bottom of the screen -------------------------
  1780.  
  1781. do_watch    movem.l    d0-d3/a0-a1,-(a7)
  1782.  
  1783.         lea.l    watch_txt,a0
  1784.         moveq    #8,d1
  1785.         move.l    watch,d0
  1786.         bsr    conv_hex
  1787.  
  1788.         lea.l    watch_txt,a0
  1789.         moveq    #31,d0
  1790.         move.w    screen_height,d1
  1791.         subq.w    #1,d1
  1792.         moveq    #8-1,d3
  1793. .print        move.b    (a0)+,d2
  1794.         bsr    print_char2
  1795.         addq.w    #1,d0
  1796.         dbf    d3,.print
  1797.  
  1798.         move.w    drive,d2
  1799.         add.b    #'0'-3,d2
  1800.         moveq    #18,d0
  1801.         move.w    screen_height,d1
  1802.         subq.w    #1,d1
  1803.         bsr    print_char2
  1804.  
  1805.         lea.l    track,a1
  1806.         move.w    drive,d0
  1807.         move.w    -3*2(a1,d0.w*2),d0
  1808.         lea.l    watch_txt,a0
  1809.         lsr.w    #1,d0
  1810.         moveq    #0,d1
  1811.         move.b    #128+2,d1
  1812.         bsr    conv_dec
  1813.         moveq    #7,d0
  1814.         move.w    screen_height,d1
  1815.         subq.w    #1,d1
  1816.         moveq    #2-1,d3
  1817.         lea.l    watch_txt+1,a0
  1818. .print2        move.b    (a0)+,d2
  1819.         bsr    print_char2
  1820.         addq.w    #1,d0
  1821.         dbf    d3,.print2
  1822.  
  1823.  
  1824.         movem.l    (a7)+,d0-d3/a0-a1
  1825.         rts
  1826.  
  1827. *******************************************************
  1828. ;print ascII page
  1829.  
  1830. print_page    movem.l    d0-d1,-(a7)
  1831.         moveq    #0,d0
  1832.         move.w    screen_height,d1
  1833.         subq.w    #1,d1
  1834. next_page_all    bsr    print_line
  1835.         addq.w    #1,d0
  1836.         dbf    d1,next_page_all
  1837.         movem.l    (a7)+,d0-d1
  1838.         rts
  1839.  
  1840. ************************************************************
  1841. ;-------------- handle all special keys --------------------
  1842. ;-------------- shift,backspace,F1-F10,etc... --------------
  1843.  
  1844. special_keys    lea.l    key,a0
  1845.         move.b    (a0),d0
  1846.         cmp.b    #$7f,d0
  1847.         beq.w    no_special_keys
  1848.  
  1849.         cmp.b    #$60,d0
  1850.         blt.b    no_shift_on
  1851.         cmp.b    #$62,d0
  1852.         bgt.b    no_shift_on
  1853.         st    shift_mode
  1854.         move.b    #$7f,(a0)
  1855.  
  1856. no_shift_on    cmp.b    #$60+$80,d0
  1857.         blt.b    no_shift_off
  1858.         cmp.b    #$62+$80,d0
  1859.         bgt.b    no_shift_off
  1860.         sf    shift_mode
  1861.         move.b    #$7f,(a0)
  1862. no_shift_off
  1863.         cmp.b    #$63,d0
  1864.         bne.b    .no_ctrl_on
  1865.         st    ctrl_mode
  1866.         move.b    #$7f,(a0)
  1867. .no_ctrl_on
  1868.         cmp.b    #$63+$80,d0
  1869.         bne.b    .no_ctrl_off
  1870.         sf    ctrl_mode
  1871.         move.b    #$7f,(a0)
  1872. .no_ctrl_off
  1873.         cmp.b    #$64,d0
  1874.         beq.b    .alt_on
  1875.         cmp.b    #$65,d0
  1876.         bne.b    .no_alt_on
  1877. .alt_on        st    alt_mode
  1878.         move.b    #$7f,(a0)
  1879. .no_alt_on
  1880.         cmp.b    #$64+$80,d0
  1881.         beq.b    .alt_off
  1882.         cmp.b    #$65+$80,d0
  1883.         bne.b    .no_alt_off
  1884. .alt_off    sf    alt_mode
  1885.         move.b    #$7f,(a0)
  1886. .no_alt_off
  1887.         cmp.b    #$66,d0
  1888.         beq.b    .amiga_on
  1889.         cmp.b    #$67,d0
  1890.         bne.b    .no_amiga_on
  1891. .amiga_on    st    amiga_mode
  1892.         move.b    #$7f,(a0)
  1893. .no_amiga_on
  1894.         cmp.b    #$66+$80,d0
  1895.         beq.b    .amiga_off
  1896.         cmp.b    #$67+$80,d0
  1897.         bne.b    .no_amiga_off
  1898. .amiga_off    sf    amiga_mode
  1899.         move.b    #$7f,(a0)
  1900. .no_amiga_off
  1901.  
  1902.         tst.b    d0
  1903.         bmi.w    no_special_keys
  1904.  
  1905.         lea.l    cursor_x,a3
  1906.  
  1907.         tst.b    trace_moni
  1908.         bne.w    no_speck1
  1909.  
  1910.         cmp.b    #$45,d0
  1911.         bne.b    no_esc
  1912.         move.b    #$7f,(a0)
  1913. no_esc
  1914.  
  1915. ;-------------- Return -------------------------------
  1916.         cmp.b    #$43,d0
  1917.         beq.b    ok_return
  1918.         cmp.b    #$44,d0
  1919.         bne.b    no_cr
  1920.  
  1921. ok_return    bsr    clear_cursor
  1922.         clr.w    (a3)
  1923.         move.b    #$7f,(a0)
  1924.  
  1925.         clr.w    (a3)
  1926.         move.w    window_bot,d1
  1927.         cmp.w    2(a3),d1
  1928.         bgt.b    ok_do_cr
  1929.         bsr    scroll_up
  1930.         subq.w    #1,2(a3)
  1931. ok_do_cr    addq.w    #1,2(a3)
  1932.  
  1933.         bsr    command_line
  1934.  
  1935.         bsr    set_cursor
  1936. no_cr
  1937. ;-------------- arrow keys --------------------------
  1938.  
  1939.         cmp.b    #$4f,d0
  1940.         bne.b    no_left
  1941.         move.b    #$7f,(a0)
  1942.         bsr    clear_cursor
  1943.         tst.b    shift_mode
  1944.         beq.b    .no_sh
  1945.         clr.w    (a3)
  1946.         bra.b    .ok_sh
  1947. .no_sh        tst.w    (a3)
  1948.         bne.b    .ok_left_edge
  1949.         move.w    #80,(a3)        ;-1 -> 79
  1950.         tst.w    2(a3)
  1951.         bne.b    .ok_top_edge
  1952.         addq.w    #1,2(a3)        ;keep 0 coz -1 later
  1953.         bsr    scroll_down
  1954. .ok_top_edge    subq.w    #1,2(a3)
  1955. .ok_left_edge    subq.w    #1,(a3)
  1956. .ok_sh        bsr    set_cursor
  1957.  
  1958. no_left        cmp.b    #$4e,d0
  1959.         bne.b    no_right
  1960.         move.b    #$7f,(a0)
  1961.         bsr    clear_cursor
  1962.         tst.b    shift_mode
  1963.         beq.b    .no_sh
  1964.         move.w    #79,(a3)
  1965.         bra.b    .ok_sh
  1966. .no_sh        cmp.w    #79,(a3)
  1967.         blt.b    .ok_right_edge
  1968.         move.w    #-1,(a3)
  1969.         move.w    window_bot,d1
  1970.         cmp.w    2(a3),d1
  1971.         bgt.b    .ok_bot_edge
  1972.         subq.w    #1,2(a3)        ;keep 24 coz +1 later
  1973.         bsr    scroll_up
  1974. .ok_bot_edge    addq.w    #1,2(a3)
  1975. .ok_right_edge    addq.w    #1,(a3)
  1976. .ok_sh        bsr    set_cursor
  1977.  
  1978. no_right
  1979.         cmp.b    #$4c,d0
  1980.         bne.w    no_up
  1981.         move.b    #$7f,(a0)
  1982.         bsr    clear_cursor
  1983.  
  1984.         tst.b    shift_mode
  1985.         beq.b    .noshift
  1986.         move.w    (2,a3),d1
  1987.         clr.w    (2,a3)            ;move cursor to top of screen
  1988.         tst.w    d1
  1989.         beq.b    .no_ctrl
  1990.         bra.w    .end_up
  1991.  
  1992. .noshift    tst.b    ctrl_mode
  1993.         beq.b    .no_ctrl
  1994.         movem.l    d0/a0,-(a7)
  1995.         clr.w    (a3)
  1996.         moveq    #16-1,d1            ;nb history lines
  1997. .loop        subq.w    #1,history_disp
  1998.         and.w    #$f,history_disp
  1999.         move.w    history_disp,d0
  2000.         mulu    #80,d0
  2001.         lea.l    history,a0
  2002.         add.l    d0,a0
  2003.         tst.b    (a0)
  2004.         dbne    d1,.loop
  2005.         bsr    print
  2006.         lea.l    79(a0),a0
  2007. .back        cmp.b    #' ',-(a0)
  2008.         bne.b    .no_spc
  2009.         subq.w    #1,(a3)
  2010.         bra.b    .back
  2011. .no_spc        movem.l    (a7)+,d0/a0
  2012.         bra.b    .end_up
  2013.  
  2014. .no_ctrl    tst.w    2(a3)
  2015.         bne.b    .ok_up
  2016.         moveq    #1,d2            ;scroll 1 line
  2017.         tst.b    shift_mode
  2018.         beq.b    .no_sh2
  2019.         clr.w    (a3)
  2020.         moveq    #SC_STEP,d2
  2021. .no_sh2        movem.l    d0-a4,-(a7)
  2022.         move.l    last_cmd,a0
  2023.         tst.l    (12,a0)
  2024.         sne    no_sc_clr
  2025.         bsr    scroll_down2
  2026.         move.l    (12,a0),d0
  2027.         beq.b    .no_up_cmd
  2028.         jsr    (d0.l)
  2029.         beq.b    .no_up_cmd
  2030.         bsr    print_page
  2031. .no_up_cmd    movem.l    (a7)+,d0-a4
  2032.         bra.b    .end_up
  2033. .ok_up        subq.w    #1,2(a3)
  2034. .end_up        bsr    set_cursor
  2035.  
  2036. no_up
  2037.         cmp.b    #$4d,d0
  2038.         bne.w    no_down
  2039.         move.b    #$7f,(a0)
  2040.         bsr    clear_cursor
  2041.  
  2042.         tst.b    shift_mode
  2043.         beq.b    .noshift
  2044.         move.w    (2,a3),d1
  2045.         move.w    window_bot,(2,a3)    ;move cursor to bot. of screen
  2046.         cmp.w    window_bot,d1
  2047.         beq.b    .no_ctrl
  2048.         bra.w    .end_down
  2049.  
  2050. .noshift    tst.b    ctrl_mode
  2051.         beq.b    .no_ctrl
  2052.         movem.l    d0/a0,-(a7)
  2053.         clr.w    (a3)
  2054.         moveq    #16-1,d1
  2055. .loop        addq.w    #1,history_disp
  2056.         and.w    #$f,history_disp
  2057.         move.w    history_disp,d0
  2058.         mulu    #80,d0
  2059.         lea.l    history,a0
  2060.         add.l    d0,a0
  2061.         tst.b    (a0)
  2062.         dbne    d1,.loop
  2063.         bsr    print
  2064.         lea.l    79(a0),a0
  2065. .back        cmp.b    #' ',-(a0)
  2066.         bne.b    .no_spc
  2067.         subq.w    #1,(a3)
  2068.         bra.b    .back
  2069. .no_spc        movem.l    (a7)+,d0/a0
  2070.         bra.b    .end_down
  2071.  
  2072. .no_ctrl    move.w    window_bot,d1
  2073.         cmp.w    2(a3),d1
  2074.         bgt.b    .ok_down
  2075.         moveq    #1,d2            ;scroll 1 line
  2076.         tst.b    shift_mode
  2077.         beq.b    .no_sh2
  2078.         clr.w    (a3)
  2079.         moveq    #SC_STEP,d2
  2080. .no_sh2        movem.l    d0-a4,-(a7)
  2081.         move.l    last_cmd,a0
  2082.         tst.l    (16,a0)
  2083.         sne    no_sc_clr
  2084.         bsr    scroll_up2
  2085.         move.l    (16,a0),d0
  2086.         beq.b    .no_down_cmd
  2087.         jsr    (d0.l)
  2088.         beq.b    .no_down_cmd
  2089.         bsr    print_page
  2090. .no_down_cmd    movem.l    (a7)+,d0-a4
  2091.         bra.b    .end_down
  2092. .ok_down    addq.w    #1,2(a3)
  2093. .end_down    bsr    set_cursor
  2094. no_down
  2095.  
  2096. ;-------------- switch Tracer page ON/OFF F7 --------------
  2097. no_speck1    cmp.b    #$56,d0
  2098.         bne.b    .no_f7
  2099.         move.b    #$7f,(a0)
  2100.         not.b    trace_moni
  2101.         beq.b    .quittracer
  2102.         bsr    clear_cursor
  2103.         move.l    #ascII_Tracer,d1
  2104.         move.w    #MAX_SCREEN,d2
  2105.         sub.w    screen_height,d2
  2106.         mulu    #80,d2
  2107.         add.l    d2,d1
  2108.         move.l    d1,ascII_ptr
  2109.         bsr    print_page
  2110.         st    trace_moni
  2111.         move.l    cursor_x,old_cursor
  2112.         st    tracer_refresh
  2113.         bra.b    .endF7
  2114.  
  2115. .quittracer    bsr    clear_cursor
  2116.         move.l    old_cursor,cursor_x
  2117.         lea.l    ascII_ptr,a1
  2118.         movem.l    4(a1),d0-d1        ;read ascII_page1,2 ptrs
  2119.         tst.b    ascII_page    ;flip page flag
  2120.         bne.b    .noex2
  2121.         exg    d0,d1
  2122. .noex2        move.l    d1,(a1)            ;set actual page ptr
  2123.         bsr    print_page
  2124.         bsr    set_cursor
  2125. .endF7
  2126.  
  2127. ;-------------- switch page 1/2 F10 -----------------------
  2128. .no_f7
  2129.         cmp.b    #$59,d0
  2130.         bne.b    no_f10
  2131.         move.b    #$7f,(a0)
  2132.         tst.b    trace_moni
  2133.         bne.b    no_f10
  2134.         bsr    clear_cursor
  2135.         lea.l    ascII_ptr,a1
  2136.         movem.l    4(a1),d1-d2        ;read ascII_page1,2 ptrs
  2137.         not.b    ascII_page    ;flip page flag
  2138.         bne.b    .noex
  2139.         exg    d1,d2
  2140. .noex        move.l    d2,(a1)            ;set actual page ptr
  2141.         bsr    print_page
  2142.         bsr    set_cursor
  2143. no_f10
  2144.  
  2145. ;-------------- Clear screen F1 -----------------
  2146.         tst.b    trace_moni
  2147.         bne.w    no_speck2
  2148.  
  2149.         cmp.b    #$50,d0
  2150.         bne.b    no_f1
  2151.         move.b    #$7f,(a0)
  2152.         bsr    clear_cursor
  2153.         move.l    ascII_ptr,a1
  2154.         move.w    window_top,d2
  2155.         mulu    #80,d2
  2156.         add.l    d2,a1
  2157.         move.l    #'    ',d1
  2158.         move.w    window_bot,d2
  2159.         sub.w    window_top,d2
  2160.         addq.w    #1,d2
  2161.         mulu    #20,d2
  2162.         subq.w    #1,d2
  2163. clear_ascII    move.l    d1,(a1)+
  2164.         dbf    d2,clear_ascII
  2165.         bsr    print_page
  2166.         moveq    #0,d1
  2167.         move.w    window_top,d1
  2168.         move.l    d1,cursor_x
  2169.         bsr    set_cursor
  2170. no_f1
  2171. ;-------------- change insert mode F2 -----------
  2172.         cmp.b    #$51,d0
  2173.         bne.b    no_f2
  2174.         move.b    #$7f,(a0)
  2175.         movem.l    d0/a0,-(a7)
  2176.         lea.l    insert_off_txt,a0
  2177.         not.b    insert_mode
  2178.         beq.b    ok_ins_off
  2179.         lea.l    insert_on_txt,a0
  2180. ok_ins_off    moveq    #76,d0
  2181.         move.w    screen_height,d1
  2182.         subq.w    #1,d1
  2183.         moveq    #3-1,d3
  2184. .loop        move.b    (a0)+,d2
  2185.         bsr    print_char2
  2186.         addq.w    #1,d0
  2187.         dbf    d3,.loop
  2188.         movem.l    (a7)+,d0/a0
  2189. no_f2
  2190.  
  2191. ;-------------- change FCPU F6 ------------------
  2192.         cmp.b    #$55,d0
  2193.         bne.b    .no_f5
  2194.         move.b    #$7f,(a0)
  2195.         tst.b    fami_mode
  2196.         beq.b    .was802
  2197.         bsr    set_65802
  2198.         bra.b    .no_f5
  2199. .was802        bsr    set_65816
  2200. .no_f5
  2201. ;-------------- backspace -----------------------
  2202.         cmp.b    #$41,d0
  2203.         bne.w    no_back
  2204.         move.b    #$7f,(a0)
  2205.         tst.b    shift_mode    ;shift+backspace -> clear line
  2206.         beq.b    .no_clr
  2207.  
  2208.         bsr    clear_cursor
  2209.         move.w    d0,-(a7)
  2210.         move.l    ascII_ptr,a1
  2211.         move.w    2(a3),d0
  2212.         mulu    #80,d0
  2213.         add.l    d0,a1
  2214.         moveq    #80-1,d0
  2215. .fill        move.b    #' ',(a1)+
  2216.         dbf    d0,.fill
  2217.         clr.w    (a3)
  2218.         move.w    2(a3),d0
  2219.         bsr    print_line
  2220.         move.w    (a7)+,d0
  2221.         bsr    set_cursor
  2222.         bra.b    no_back
  2223.  
  2224. .no_clr        tst.w    (a3)
  2225.         beq.b    no_back
  2226.         bsr    clear_cursor
  2227.         move.l    ascII_ptr,a1
  2228.         add.w    (a3),a1            ;add x cursor
  2229.         subq.w    #1,a1
  2230.         move.w    2(a3),d1
  2231.         mulu    #80,d1
  2232.         add.l    d1,a1            ;add y cursor
  2233.         lea.l    1(a1),a2
  2234.         moveq    #80-1,d1
  2235.         sub.w    (a3),d1
  2236. scroll_line    move.b    (a2)+,(a1)+
  2237.         dbf    d1,scroll_line
  2238.         move.b    #' ',(a1)+
  2239.         move.w    d0,-(a7)
  2240.         move.w    2(a3),d0
  2241.         bsr    print_line
  2242.         move.w    (a7)+,d0
  2243.         subq.w    #1,(a3)
  2244.         bsr    set_cursor
  2245. no_back
  2246. ;-------------- del -----------------------------
  2247.         cmp.b    #$46,d0
  2248.         bne.b    no_del
  2249.         move.b    #$7f,(a0)
  2250.         bsr    clear_cursor
  2251.  
  2252.         tst.b    shift_mode
  2253.         beq.b    .do_del
  2254.  
  2255.         move.l    ascII_ptr,a1
  2256.         move.w    2(a3),d1
  2257.         mulu    #80,d1
  2258.         add.l    d1,a1
  2259.         lea.l    80(a1),a1
  2260.         lea.l    -1(a1),a2
  2261.         moveq    #80-2,d1
  2262.         sub.w    (a3),d1
  2263.         bmi.b    end_del
  2264. .l        move.b    -(a2),-(a1)
  2265.         dbf    d1,.l
  2266.         move.b    #' ',(a2)
  2267.         bra.b    end_del
  2268.  
  2269. .do_del        move.l    ascII_ptr,a1
  2270.         add.w    (a3),a1            ;add x cursor
  2271.         move.w    2(a3),d1
  2272.         mulu    #80,d1
  2273.         add.l    d1,a1            ;add y cursor
  2274.         lea.l    1(a1),a2
  2275.         moveq    #80-1,d1
  2276.         sub.w    (a3),d1
  2277.         bra.b    do_dbf_scroll
  2278. scroll_line2    move.b    (a2)+,(a1)+
  2279. do_dbf_scroll    dbf    d1,scroll_line2
  2280.         move.b    #' ',(a1)+
  2281. end_del        move.w    d0,-(a7)
  2282.         move.w    2(a3),d0
  2283.         bsr    print_line
  2284.         move.w    (a7)+,d0
  2285.         bsr    set_cursor
  2286.  
  2287. no_del
  2288. ;-------------- HELP print help page ---------------
  2289.  
  2290.         cmp.b    #$5f,d0
  2291.         bne.b    no_help
  2292.         move.b    #$7f,(a0)
  2293.         move.l    a0,-(a7)
  2294.         lea.l    help_txt,a0
  2295.         bsr    print_curs
  2296.         tst.b    break
  2297.         beq.b    .nobrk
  2298.         sf    break
  2299.         lea.l    break_txt,a0
  2300.         bsr    print
  2301. .nobrk        move.l    (a7)+,a0
  2302. no_help
  2303. no_speck2
  2304. no_special_keys    rts
  2305.  
  2306. ;------------------------------------------------
  2307. ;-------------- handle normal keys --------------
  2308. ;-------------- 0-9,a-z,etc... ------------------
  2309.  
  2310. normal_keys    lea.l    key,a0
  2311.         tst.b    snap_buf
  2312.         beq.b    .nos
  2313.         move.b    #$40,(a0)
  2314. .nos        moveq    #0,d0
  2315.         move.b    (a0),d0
  2316.         cmp.b    #$7f,d0
  2317.         beq.w    no_normal_keys
  2318.  
  2319.         move.b    #$7f,(a0)
  2320.  
  2321.         tst.b    d0
  2322.         bmi.w    no_normal_keys
  2323.  
  2324.         bsr    clear_cursor
  2325.  
  2326.         move.l    board_ptr,a1
  2327.         tst.b    shift_mode
  2328.         beq.b    no_shift_mode
  2329.         move.l    board_ptr+4,a1
  2330. no_shift_mode    tst.b    alt_mode
  2331.         beq.b    .no_alt
  2332.         move.l    board_ptr+8,a1
  2333. .no_alt        move.b    (a1,d0.w),d2
  2334.  
  2335.         move.l    a0,-(a7)
  2336.         lea.l    snap_buf,a0
  2337.         tst.b    (a0)
  2338.         beq.b    empty_snap
  2339.  
  2340. resnap        move.b    (a0)+,d2
  2341.  
  2342. empty_snap    lea.l    cursor_x,a3
  2343.  
  2344.         tst.b    insert_mode
  2345.         beq.b    no_insert_mode
  2346. ;-------------- do insert mode -----------------
  2347.         cmp.w    #79,(a3)
  2348.         bge.b    ok_cursor_pos
  2349.         move.l    ascII_ptr,a1
  2350.         move.l    a1,a2
  2351.         add.w    (a3),a1
  2352.         move.w    2(a3),d0
  2353.         mulu    #80,d0
  2354.         add.l    d0,a1
  2355.         add.l    d0,a2
  2356.         lea.l    80(a2),a2
  2357.         lea.l    -1(a2),a4
  2358. do_insert    move.b    -(a4),-(a2)
  2359.         cmp.l    a1,a4
  2360.         bne.b    do_insert
  2361.         move.b    d2,(a1)
  2362.         addq.w    #1,(a3)
  2363.         move.w    2(a3),d0
  2364.         bsr    print_line
  2365.         bra.b    ok_cursor_pos
  2366. ;-----------------------------------------------
  2367. no_insert_mode
  2368.         movem.w    (a3),d0-d1
  2369.         bsr    print_char
  2370.  
  2371.         addq.w    #1,(a3)
  2372.         cmp.w    #80,(a3)
  2373.         blt.b    ok_cursor_pos
  2374.         clr.w    (a3)
  2375.         move.w    window_bot,d1
  2376.         cmp.w    2(a3),d1
  2377.         bgt.b    ok_cursor_h
  2378.         bsr    scroll_up
  2379.         bra.b    ok_cursor_pos
  2380. ok_cursor_h    addq.w    #1,2(a3)
  2381.  
  2382. ok_cursor_pos
  2383.         tst.b    (a0)
  2384.         bne.w    resnap
  2385.  
  2386.         sf    snap_buf
  2387.  
  2388.         move.l    (a7)+,a0
  2389.  
  2390.         bsr    set_cursor
  2391.  
  2392. no_normal_keys    rts
  2393.  
  2394. ************************************************************
  2395. ;-------------- called when RETURN is pressed --------------
  2396.  
  2397. command_line    movem.l    d0-d7/a0-a4,-(a7)
  2398.         lea.l    cursor_x,a3
  2399.         move.w    2(a3),d0        ;read y pos
  2400.         subq.w    #1,d0
  2401.         move.l    ascII_ptr,a0
  2402.         mulu    #80,d0
  2403.         add.l    d0,a0
  2404.         lea.l    command,a1
  2405.         moveq    #80-1,d1
  2406. copy_command    move.b    (a0)+,(a1)+        ;copy current line into
  2407.         dbf    d1,copy_command        ;command
  2408.  
  2409.         sf    d4            ;command repeat signal off
  2410.         lea.l    command,a0
  2411. seek_command    move.b    (a0)+,d0        ;seek command first char
  2412.         beq.b    end_cmd_line
  2413.         cmp.b    #$20,d0
  2414.         beq.b    seek_command
  2415.         bra.b    ok_new_cmd
  2416.  
  2417. end_cmd_line    subq.w    #1,2(a3)        ;if command line is empty
  2418.         move.l    last_cmd,a0        ;then repeat last command
  2419.         addq.l    #1,a0
  2420.         st    d4            ;signal in d4 for cmd repeat
  2421. ok_new_cmd
  2422.         subq.l    #1,a0
  2423.         lea.l    cmd_list,a2
  2424.         moveq    #0,d1            ;command code offset cleared
  2425.  
  2426. .loop2        tst.b    (a2)            ;search if command
  2427.         beq.b    end_cmd_list        ;exists
  2428.         move.l    a2,a3
  2429.         move.l    a0,a1
  2430. .loop        move.b    (a3)+,d3
  2431.         beq.b    .ok_cmp
  2432.         move.b    (a1)+,d0
  2433.         bsr    upper_case
  2434.         cmp.b    d0,d3
  2435.         beq.b    .loop
  2436.  
  2437. .go1        lea.l    20(a2),a2        ;next command in cmd_list
  2438.         bra.b    .loop2
  2439.  
  2440. .ok_cmp        move.l    8(a2),d1        ;command code offset
  2441.         cmp.l    #cmd_x,d1
  2442.         beq.b    .nolast            ;cant't repeat cmd_x
  2443.         move.l    a2,last_cmd
  2444. .nolast        move.l    a1,d2
  2445.         bra.b    .go1            ;check if it's really this cmd
  2446.                         ;to get the longest cmd.
  2447.  
  2448. end_cmd_list    sf    break
  2449.         tst.l    d1
  2450.         beq.b    no_command
  2451.  
  2452.         tst.b    d4            ;test if cmd repeat ?
  2453.         bne.b    .no_hist
  2454.  
  2455.         lea.l    history_cnt,a2
  2456.         move.w    (a2),d0
  2457.         lea.l    history,a0
  2458.         mulu    #80,d0
  2459.         add.l    d0,a0
  2460.         lea.l    command,a1
  2461.         moveq    #79-1,d0
  2462. .copy        move.b    (a1)+,(a0)+        ;copy command in history
  2463.         dbf    d0,.copy
  2464.  
  2465.         addq.w    #1,(a2)
  2466.         and.w    #$f,(a2)        ;maxi 16 history lines
  2467.         move.w    (a2),history_disp
  2468.  
  2469. .no_hist    st    no_curs
  2470.         move.l    d2,a0
  2471.         lea.l    cmd_list(pc),a5
  2472.         jmp    (d1.l)            ;execute the command
  2473.  
  2474. no_command    lea.l    unknown_txt,a0
  2475.         bsr    print
  2476.  
  2477. end_command
  2478.         tst.b    break            ;ESC pressed during
  2479.         beq.b    .no_break        ;command ?
  2480.         sf    break
  2481.         lea.l    break_txt,a0
  2482.         bsr    print
  2483. .no_break
  2484.         sf    no_curs
  2485.  
  2486.         movem.l    (a7)+,d0-d7/a0-a4
  2487.         rts
  2488.  
  2489. ************************************************************
  2490.         cnop 0,4
  2491.  
  2492. ;-------------- cmds ordered by size -----------------------
  2493. ;cmd format
  2494. ;----------
  2495. ;dc.b cmd name padded with 0 (8 bytes)
  2496. ;dc.l ptr to code, ptr to line up code, ptr to line down code
  2497.  
  2498. cmd_list:    dc.b 'R',0,0,0,0,0,0,0
  2499.         dc.l cmd_r,0,0
  2500.         dc.b 'H',0,0,0,0,0,0,0
  2501.         dc.l cmd_h,cmdu_h,cmdd_h
  2502.         dc.b 'M',0,0,0,0,0,0,0
  2503.         dc.l cmd_h,cmdu_h,cmdd_h
  2504.         dc.b 'D',0,0,0,0,0,0,0
  2505.         dc.l cmd_a,cmdu_d,cmdd_d
  2506.         dc.b 'B',0,0,0,0,0,0,0
  2507.         dc.l cmd_b,0,0
  2508.         dc.b 'C',0,0,0,0,0,0,0
  2509.         dc.l cmd_c,0,0
  2510.         dc.b 'T',0,0,0,0,0,0,0
  2511.         dc.l cmd_t,0,0
  2512.         dc.b 'N',0,0,0,0,0,0,0
  2513.         dc.l cmd_n,cmdu_n,cmdd_n
  2514.         dc.b 'P',0,0,0,0,0,0,0
  2515.         dc.l cmd_p,0,0
  2516.         dc.b '?',0,0,0,0,0,0,0
  2517.         dc.l cmd_ev,0,0
  2518.         dc.b 'L',0,0,0,0,0,0,0
  2519.         dc.l cmd_l,0,0
  2520.         dc.b 'X',0,0,0,0,0,0,0
  2521.         dc.l cmd_x,0,0
  2522.         dc.b 'G',0,0,0,0,0,0,0
  2523.         dc.l cmd_g,0,0
  2524.         dc.b 'F',0,0,0,0,0,0,0
  2525.         dc.l cmd_f,0,0
  2526.         dc.b 'O',0,0,0,0,0,0,0
  2527.         dc.l cmd_o,0,0
  2528.         dc.b 'A',0,0,0,0,0,0,0
  2529.         dc.l cmd_a,0,0
  2530.         dc.b 'S',0,0,0,0,0,0,0
  2531.         dc.l cmd_s,0,0
  2532.         dc.b 'Q',0,0,0,0,0,0,0
  2533.         dc.l cmd_q,0,0
  2534.         dc.b 'E',0,0,0,0,0,0,0
  2535.         dc.l cmd_e,cmdu_e,cmdd_e
  2536.  
  2537.         dc.b 'FI',0,0,0,0,0,0
  2538.         dc.l cmd_fi,0,0
  2539.         dc.b 'RS',0,0,0,0,0,0
  2540.         dc.l cmd_disk1,0,0
  2541.         dc.b 'WS',0,0,0,0,0,0
  2542.         dc.l cmd_disk2,0,0
  2543.         dc.b 'CD',0,0,0,0,0,0
  2544.         dc.l cmd_cd,0,0
  2545.         dc.b 'DF',0,0,0,0,0,0
  2546.         dc.l cmd_df,0,0
  2547.         dc.b 'AF',0,0,0,0,0,0
  2548.         dc.l cmd_af,0,0
  2549.         dc.b 'TS',0,0,0,0,0,0
  2550.         dc.l cmd_ts,0,0
  2551.         dc.b 'TF',0,0,0,0,0,0
  2552.         dc.l cmd_tf,0,0
  2553.         dc.b 'SA',0,0,0,0,0,0
  2554.         dc.l cmd_sa,0,0
  2555.         dc.b 'LA',0,0,0,0,0,0
  2556.         dc.l cmd_la,0,0
  2557.         dc.b 'LS',0,0,0,0,0,0
  2558.         dc.l cmd_dir,0,0
  2559.         dc.b 'SP',0,0,0,0,0,0
  2560.         dc.l cmd_sp,0,0
  2561.         dc.b 'BB',0,0,0,0,0,0
  2562.         dc.l cmd_bb,0,0
  2563.         dc.b 'FS',0,0,0,0,0,0
  2564.         dc.l cmd_fs,0,0
  2565.  
  2566.         dc.b 'TSD',0,0,0,0,0
  2567.         dc.l cmd_tsd,0,0
  2568.          dc.b 'FIF',0,0,0,0,0
  2569.         dc.l cmd_fif,0,0
  2570.         dc.b 'DIR',0,0,0,0,0
  2571.         dc.l cmd_dir,0,0
  2572.         dc.b 'PAL',0,0,0,0,0
  2573.         dc.l cmd_pal,0,0
  2574.         dc.b '31K',0,0,0,0,0
  2575.         dc.l cmd_31k,0,0
  2576.         dc.b 'LED',0,0,0,0,0
  2577.         dc.l cmd_led,0,0
  2578.         dc.b 'IDE',0,0,0,0,0
  2579.         dc.l cmd_ide,0,0
  2580.         dc.b 'DEL',0,0,0,0,0
  2581.         dc.l cmd_del,0,0
  2582.         dc.b 'PWD',0,0,0,0,0
  2583.         dc.l cmd_cd,0,0
  2584.         dc.b 'D2F',0,0,0,0,0
  2585.         dc.l cmd_d2f,0,0
  2586.         dc.b 'F2D',0,0,0,0,0
  2587.         dc.l cmd_f2d,0,0
  2588.         dc.b 'VER',0,0,0,0,0
  2589.         dc.l cmd_ver,0,0
  2590.         dc.b 'SAC',0,0,0,0,0
  2591.         dc.l cmd_sac,0,0
  2592.         dc.b 'COP',0,0,0,0,0
  2593.         dc.l cmd_cop,0,0
  2594.  
  2595.         dc.b 'NTSC',0,0,0,0
  2596.         dc.l cmd_ntsc,0,0
  2597.         dc.b 'TYPE',0,0,0,0
  2598.         dc.l cmd_type,0,0
  2599.         dc.b 'COPY',0,0,0,0
  2600.         dc.l cmd_copy,0,0
  2601.         dc.b 'PART',0,0,0,0
  2602.         dc.l cmd_part,0,0
  2603.         dc.b 'KILL',0,0,0,0
  2604.         dc.l cmd_kill,0,0
  2605.  
  2606.         dc.b 'DRIVE',0,0,0
  2607.         dc.l cmd_drive,0,0
  2608.         dc.b 'DEBUG',0,0,0
  2609.         dc.l cmd_debug,0,0
  2610.         dc.b 'MOTOR',0,0,0
  2611.         dc.l cmd_motor,0,0
  2612.         dc.b 'INTEL',0,0,0
  2613.         dc.l cmd_intel,0,0
  2614.         dc.b 'EXCEP',0,0,0
  2615.         dc.l cmd_excep,0,0
  2616.         dc.b 'MKDIR',0,0,0
  2617.         dc.l cmd_makedir,0,0
  2618.         dc.b 'CLEAR',0,0,0
  2619.         dc.l cmd_clear,0,0
  2620.  
  2621.         dc.b 'REBOOT',0,0
  2622.         dc.l cmd_reboot,0,0
  2623.         dc.b 'FORMAT',0,0
  2624.         dc.l cmd_format,0,0
  2625.         dc.b 'OUTPUT',0,0
  2626.         dc.l cmd_output,0,0
  2627.         dc.b 'SETMAP',0,0
  2628.         dc.l cmd_setmap,0,0
  2629.         dc.b 'HORNET',0,0
  2630.         dc.l cmd_hornet,0,0
  2631.         dc.b 'CHKDSK',0,0
  2632.         dc.l cmd_diskchk,0,0
  2633.  
  2634.         dc.b 'FORMATQ',0
  2635.         dc.l cmd_formatq,0,0
  2636.         dc.b 'DISKCHK',0
  2637.         dc.l cmd_diskchk,0,0
  2638.         dc.b 'MAKEDIR',0
  2639.         dc.l cmd_makedir,0,0
  2640.  
  2641.         dcb.b 8,0
  2642.         dc.l 0,0,0
  2643.  
  2644. ****************************************************************
  2645.  
  2646. cmd_ver        lea.l    ver_txt(pc),a0
  2647.         bsr    print
  2648.         bra.w    end_command
  2649.  
  2650. ver_txt        dc.b "HRTmon v"
  2651.         version            ;x.yz
  2652.         dc.b $a,0
  2653.         even
  2654.  
  2655. ****************************************************************
  2656.  
  2657.         include src/copper.s
  2658.  
  2659. ****************************************************************
  2660. ;-------------- FS find string (not casesensitive) -------------
  2661.  
  2662. cmd_fs        bsr    evaluate
  2663.         bne.w    illegal_addr
  2664.         move.l    d0,find_start
  2665.         bsr    evaluate
  2666.         bne.w    illegal_addr
  2667.         move.l    d0,find_end
  2668.         movem.l    find_start,d0-d1
  2669.         cmp.l    d0,d1
  2670.         ble.w    illegal_addr
  2671.  
  2672.         lea.l    find_list,a1
  2673.         bsr    read_name
  2674.         tst.b    (a1)
  2675.         beq.w    illegal_string
  2676.  
  2677. .up        move.b    (a1),d0
  2678.         beq.b    .endlist
  2679.         bsr    upper_case
  2680.         move.b    d0,(a1)+
  2681.         bra.b    .up
  2682. .endlist
  2683.         movem.l    find_start,a0-a1
  2684.  
  2685.         lea.l    watch,a3
  2686.         move.l    a0,(a3)
  2687.  
  2688. .seek        tst.b    break
  2689.         bne.w    .endfs
  2690.         lea.l    find_list,a2
  2691.         move.b    (a2)+,d1
  2692. .next        cmp.l    a1,a0
  2693.         bge.w    .endfs
  2694.         move.l    a0,(a3)
  2695.         move.l    a0,a4
  2696.         CORR_ADDR 1
  2697.         move.b    (a4),d0
  2698.         addq.l    #1,a0
  2699.         bsr    upper_case
  2700.         cmp.b    d0,d1
  2701.         bne.b    .next
  2702.  
  2703.         move.l    a0,d7
  2704. .ok        move.b    (a2)+,d1
  2705.         beq.b    .found
  2706.         cmp.l    a1,a0
  2707.         bge.b    .endfs
  2708.         move.l    a0,a4
  2709.         CORR_ADDR 2
  2710.         addq.l    #1,a0
  2711.         move.b    (a4),d0
  2712.         bsr    upper_case
  2713.         cmp.b    d0,d1
  2714.         beq.b    .ok
  2715.         move.l    d7,a0
  2716.         bra.b    .seek
  2717.  
  2718. .found        move.l    d7,d0
  2719.         subq.l    #1,d0
  2720.         lea.l    ev_line,a0
  2721.         move.w    #$2020,8(a0)
  2722.         clr.b    10(a0)
  2723.         moveq    #8,d1
  2724.         bsr    conv_hex
  2725.         bsr    print
  2726.         move.l    d7,a0
  2727.         bra.w    .seek
  2728.  
  2729. .endfs
  2730.         tst.w    cursor_x
  2731.         beq.b    .no_CR
  2732.         lea.l    cr_txt,a0
  2733.         bsr    print
  2734. .no_CR
  2735.         bra.w    end_command
  2736.  
  2737. ****************************************************************
  2738.  
  2739. cmd_clear
  2740.         lea.l    sureclear_txt(pc),a0
  2741.         bsr    print
  2742.         bsr    get_key
  2743.         lea.l    sure2_txt(pc),a0
  2744.         bsr    print
  2745.         cmp.b    #'y',d0
  2746.         bne.b    .no
  2747.         bsr    remove_pic
  2748.         lea.l    $0.w,a0
  2749.         moveq    #0,d0
  2750.         moveq    #-1,d1
  2751. .clear        rept 8
  2752.         move.l    d0,(a0)+
  2753.         endr
  2754.         dbf    d1,.clear
  2755.         bsr    set_pic
  2756.         move.l    $f80004,a0
  2757.         subq.l    #2,a0
  2758.         move.l    a0,pc_reg
  2759.         move.w    #$2700,sr_reg
  2760.         st    escape
  2761.  
  2762. .no        bra.w    end_command
  2763.  
  2764. sureclear_txt    dc.b "All memory will be cleared and the machine will reboot!",$a
  2765.         dc.b "(You will have to reinstall HRTmon)",$a
  2766.         dc.b "Are you sure you want to continue ? (y/n)",$d,0
  2767. sure2_txt    dc.b "                                         ",$d,0
  2768.         even
  2769.  
  2770. ****************************************************************
  2771. ;-------------- SETMAP change keymap ----------------------
  2772.  
  2773. cmd_setmap    lea.l    ev_line,a1
  2774.         bsr    read_name
  2775.         tst.b    (a1)            ;keymap name given ?
  2776.         beq.w    .noset
  2777.  
  2778.         lea.l    ev_line,a0
  2779. .up        move.b    (a0),d0
  2780.         bsr    upper_case
  2781.         move.b    d0,(a0)+        ;upper-case keymap name
  2782.         tst.b    (a0)
  2783.         bne.b    .up
  2784.  
  2785.         lea.l    ev_line,a0
  2786.         cmp.l    #"USA"*256,(a0)
  2787.         bne.b    .noUSAset
  2788.         move.l    #board3,d0
  2789.         move.l    #board4,d1
  2790.         move.l    #board4a,d2
  2791.         bra.b    .set
  2792. .noUSAset    cmp.w    #"CH",(a0)
  2793.         bne.b    .noCHset
  2794.         tst.b    2(a0)
  2795.         bne.b    .noCHset
  2796.         move.l    #board1,d0
  2797.         move.l    #board2,d1
  2798.         move.l    #board2a,d2
  2799.         bra.b    .set
  2800. .noCHset    cmp.w    #"D"*256,(a0)
  2801.         bne.b    .noDset
  2802.         move.l    #board5,d0
  2803.         move.l    #board6,d1
  2804.         move.l    #board6a,d2
  2805.         bra.b    .set
  2806. .noDset        cmp.w    #"F"*256,(a0)
  2807.         bne.b    .noFset
  2808.         move.l    #board7,d0
  2809.         move.l    #board8,d1
  2810.         move.l    #board8a,d2
  2811.         bra.b    .set
  2812. .noFset
  2813.         lea.l    .maperr_txt(pc),a0
  2814.         bsr    print
  2815.         bra.b    .noset
  2816.  
  2817. .set        movem.l    d0-d2,board_ptr
  2818.  
  2819. .noset        lea.l    .key1_txt(pc),a0
  2820.         bsr    print
  2821.  
  2822.         move.l    board_ptr,d0
  2823.         cmp.l    #board3,d0
  2824.         bne.b    .noUSA
  2825.         lea.l    .key2_txt(pc),a0
  2826. .noUSA        cmp.l    #board1,d0
  2827.         bne.b    .noCH
  2828.         lea.l    .key3_txt(pc),a0
  2829. .noCH        cmp.l    #board5,d0
  2830.         bne.b    .noD
  2831.         lea.l    .key4_txt(pc),a0
  2832. .noD        cmp.l    #board7,d0
  2833.         bne.b    .noF
  2834.         lea.l    .key5_txt(pc),a0
  2835. .noF        bsr    print
  2836.  
  2837.         bra.w    end_command
  2838.  
  2839. .maperr_txt    dc.b "Illegal keymap name !",$a,0
  2840. .key1_txt    dc.b "Actual keymap is : ",0
  2841. .key2_txt    dc.b "USA",$a,0
  2842. .key3_txt    dc.b "CH",$a,0
  2843. .key4_txt    dc.b "D",$a,0
  2844. .key5_txt    dc.b "F",$a,0
  2845.         even
  2846.  
  2847. ;-------------- print exception vectors and names --------------
  2848.  
  2849. cmd_excep    lea.l    Vector_names,a4
  2850.         move.l    vbr_reg,a3
  2851. .loop        move.w    (a4)+,d2
  2852.         bmi.b    .end
  2853.         lea.l    .txt(pc),a0
  2854.         bsr    print
  2855.         move.l    (a3,d2.w),d0
  2856.         cmp.l    #start,d0
  2857.         blt.b    .ok
  2858.         cmp.l    #end,d0
  2859.         bge.b    .ok
  2860.         move.l    (d2.w),d0
  2861. .ok        moveq    #8,d1
  2862.         bsr    print_hex
  2863.         move.l    (a4)+,a0
  2864.         bsr    print
  2865.         bra.b    .loop
  2866.  
  2867. .end
  2868.         bra.w    end_command
  2869.  
  2870. .txt        dc.b "$",0
  2871.         even
  2872.  
  2873. ;-------------- disk to file -----------------------------------
  2874. ;-------------- read a whole disk and save it as a file --------
  2875.  
  2876. cmd_d2f
  2877.         lea.l    ev_line,a1
  2878.         bsr    read_name
  2879.         tst.b    (a1)
  2880.         beq.w    illegal_name
  2881.  
  2882.         bsr    test_present
  2883.         bne.w    .error
  2884.  
  2885.         move.l    #ev_line,d1
  2886.         moveq    #-1,d2        ;create new file
  2887.         bsr    open_file
  2888.         move.l    d0,d7
  2889.         beq.b    .error
  2890.  
  2891.         move.w    #-1,ts_size        ;trainer buffer cleared
  2892.  
  2893.         moveq    #0,d5
  2894.         move.w    #160-1,d6
  2895. .next        move.l    #tmp_mem,a0
  2896.         move.l    d5,d0
  2897.         moveq    #11,d1
  2898.         bsr    read2
  2899.         bne.b    .error
  2900.         add.l    d1,d5
  2901.         move.l    d7,d1
  2902.         move.l    #tmp_mem,d2
  2903.         move.l    #512*11,d3
  2904.         bsr    write_file
  2905.         bne.b    .error
  2906.         tst.b    break
  2907.         bne.b    .close
  2908.         dbf    d6,.next
  2909.  
  2910. .close        move.l    d7,d1
  2911.         bsr    close_file
  2912. .error
  2913.  
  2914.         bra.w    end_disk
  2915.  
  2916.  
  2917. ;-------------- file to disk -----------------------------------
  2918. ;-------------- read a file and write it to disk ---------------
  2919.  
  2920. cmd_f2d        lea.l    ev_line,a1
  2921.         bsr    read_name
  2922.         tst.b    (a1)
  2923.         beq.w    illegal_name
  2924.  
  2925.         bsr    test_present
  2926.         bne.w    .error
  2927.  
  2928.         move.l    #ev_line,d1
  2929.         moveq    #0,d2        ;open old file
  2930.         bsr    open_file
  2931.         move.l    d0,d7
  2932.         beq.w    .error
  2933.         move.l    d7,a0
  2934.         cmp.l    #80*22*512,file_size(a0)
  2935.         beq.b    .oksize
  2936.         lea.l    sizeErr_txt(pc),a0
  2937.         bsr    print
  2938.         bra.b    .error
  2939.  
  2940. .oksize
  2941.  
  2942.         move.w    #-1,ts_size        ;trainer buffer cleared
  2943.  
  2944.         moveq    #0,d5
  2945.         move.w    #160-1,d6
  2946. .next        move.l    d7,d1
  2947.         move.l    #tmp_mem,d2
  2948.         move.l    #512*11,d3
  2949.         bsr    read_file
  2950.         bne.b    .error
  2951.         move.l    #tmp_mem,a0
  2952.         move.l    d5,d0
  2953.         moveq    #11,d1
  2954.         bsr    write2
  2955.         bne.b    .error
  2956.         add.l    d1,d5
  2957.         tst.b    break
  2958.         bne.b    .close
  2959.         dbf    d6,.next
  2960.  
  2961. .close        move.l    d7,d1
  2962.         bsr    close_file
  2963. .error
  2964.  
  2965.         bra.w    end_disk
  2966.  
  2967. sizeErr_txt    dc.b "Wrong file size !",$a,0
  2968.         even
  2969.  
  2970. ;-------------- show custom registers --------------------------
  2971.  
  2972. cmd_e        bsr    evaluate
  2973.         bne.b    .no_offset
  2974.         cmp.l    #$200,d0
  2975.         bge.w    illegal_addr
  2976.         btst    #0,d0
  2977.         bne.w    illegal_addr
  2978.         move.l    d0,custom_offset
  2979.         move.l    d0,d3
  2980.         bsr    evaluate        ;edit ?
  2981.         bne.b    .no_offset
  2982.         lea.l    custom,a3
  2983.         move.w    d0,(a3,d3.l)
  2984.         bra.w    end_command
  2985.  
  2986. .no_offset    move.l    custom_offset,d5
  2987.         moveq    #8-1,d7            ;print 8 lines
  2988. .loop        cmp.l    #$200,d5
  2989.         bge.b    .noprint
  2990.  
  2991.         bsr    make_e_line
  2992.  
  2993.         addq.l    #2,d5
  2994.         lea.l    general_txt,a0
  2995.         bsr    print
  2996.         dbf    d7,.loop
  2997.  
  2998. .noprint    move.l    d5,custom_offset
  2999.  
  3000.         bra.w    end_command
  3001.  
  3002. ;-> d5=offset
  3003. ;<- general_txt filled with e_line
  3004. make_e_line    movem.l    d0-a4,-(a7)
  3005.         lea.l    custom_names,a2
  3006.         lea.l    custom,a3
  3007.         lea.l    general_txt,a0
  3008.         move.w    #"e ",(a0)+
  3009.         move.b    #"$",(a0)+
  3010.         moveq    #3,d1
  3011.         move.w    d5,d0
  3012.         bsr    conv_hex        ;print offset
  3013.         add.l    d1,a0
  3014.         move.w    #" $",(a0)+
  3015.         move.w    (a3,d5.w),d0
  3016.         moveq    #4,d1
  3017.         bsr    conv_hex        ;print register value
  3018.         add.l    d1,a0
  3019.         move.l    #"  ; ",(a0)+
  3020.         lea.l    (a2,d5.w*4),a4
  3021.         move.l    (a4)+,(a0)+
  3022.         move.l    (a4)+,(a0)+
  3023.         move.w    #$0a00,(a0)+
  3024.         movem.l    (a7)+,d0-a4
  3025.         rts
  3026.  
  3027. ;-------------- scroll up e_line -----------
  3028.  
  3029. cmdu_e        move.l    ascII_ptr,a0
  3030.         lea.l    80(a0),a0
  3031.         cmp.w    #'e ',(a0)    ;last top line was an e_line ?
  3032.         bne.b    .noe
  3033.         addq.l    #2,a0
  3034.         bsr    evaluate    ;get last offset
  3035.         subq.l    #2,d0
  3036.         bmi.b    .noe
  3037.  
  3038.         move.l    d0,d5
  3039.         bsr.b    make_e_line
  3040.  
  3041.         lea.l    general_txt,a0
  3042.         bsr    print
  3043.         subq.w    #1,(2,a3)    ;cursor one line up
  3044.  
  3045.         moveq    #0,d0
  3046.  
  3047. .noe        rts
  3048.  
  3049. ;-------------- scroll down e_line ---------
  3050.  
  3051. cmdd_e        move.l    ascII_ptr,a0
  3052.         move.l    d0,-(a7)
  3053.         move.w    window_bot,d0
  3054.         subq.w    #2,d0
  3055.         mulu    #80,d0
  3056.         add.l    d0,a0
  3057.         move.l    (a7)+,d0
  3058.         cmp.w    #'e ',(a0)    ;last line was an e_line ?
  3059.         bne.b    .noe
  3060.         addq.l    #2,a0
  3061.         bsr    evaluate    ;get last address
  3062.         addq.l    #2,d0
  3063.         cmp.l    #$200,d0
  3064.         bge.b    .noe
  3065.  
  3066.         move.l    d0,d5
  3067.         bsr    make_e_line
  3068.  
  3069.         addq.l    #2,d5
  3070.         move.l    d5,custom_offset
  3071.  
  3072.         subq.w    #1,(2,a3)        ;cursor one line up
  3073.         lea.l    general_txt,a0
  3074.         bsr    print
  3075.  
  3076.         moveq    #0,d0
  3077.  
  3078. .noe        rts
  3079.  
  3080.  
  3081. ;-------------- delete a file or an empty dir ------------------
  3082.  
  3083. cmd_del        lea.l    ev_line,a1
  3084.         bsr    read_name        ;get source name
  3085.         tst.b    (a1)
  3086.         beq.w    illegal_name
  3087.  
  3088.         move.l    #ev_line,d1
  3089.         bsr    delete_file
  3090.  
  3091.         bra.w    end_disk
  3092.  
  3093. ;-------------- get partition info -----------------------------
  3094.  
  3095. cmd_part
  3096.  
  3097.         move.l    #floppy0,d0
  3098.  
  3099.         lea.l    part_txt(pc),a0
  3100.         bsr    print
  3101.  
  3102. .next        move.l    d0,a4
  3103.  
  3104.  
  3105.         lea.l    part_name(a4),a0
  3106.         lea.l    general_txt,a1
  3107.         move.l    a1,a2
  3108.         moveq    #8-1,d0
  3109. .fill        move.l    #"    ",(a2)+
  3110.         dbf    d0,.fill
  3111.  
  3112.         moveq    #0,d0
  3113.         move.b    (a0)+,d0
  3114.         bra.b    .godbf
  3115. .copy        move.b    (a0)+,(a1)+        ;copy name
  3116. .godbf        dbf    d0,.copy
  3117.         lea.l    part2_txt(pc),a0
  3118.         bsr    print
  3119.         lea.l    general_txt,a0
  3120.         sf    16(a0)
  3121.         bsr    print            ;print name
  3122.  
  3123.         lea.l    part3_txt(pc),a0
  3124.         cmp.l    #ide_device,part_device(a4)
  3125.         beq.b    .ide
  3126.         lea.l    part4_txt(pc),a0
  3127. .ide        bsr    print            ;device
  3128.  
  3129.         move.l    part_first(a4),d0
  3130.         moveq    #8,d1
  3131.         bsr    print_dec
  3132.  
  3133.         lea.l    part5_txt(pc),a0
  3134.         bsr    print
  3135.  
  3136.         move.l    part_nbsec(a4),d0
  3137.         moveq    #8,d1
  3138.         bsr    print_decCR
  3139.  
  3140.         move.l    part_next(a4),d0
  3141.         bne.b    .next
  3142.  
  3143.         bra.w    end_command
  3144.  
  3145. part_txt
  3146.  dc.b "--- Name ----------- -- Device -- -- First Block ----- -- NbBlocks --------",$a,0
  3147.  
  3148. part2_txt    dc.b "     ",0
  3149. part5_txt    dcb.b 11,$20
  3150.         dc.b 0
  3151.  
  3152. part3_txt    dc.b "    IDE       ",0
  3153. part4_txt    dc.b "    Floppy    ",0
  3154.         even
  3155.  
  3156. ;-------------- get info from IDE drives -----------------------
  3157.  
  3158. cmd_ide        tst.b    config_IDE
  3159.         bne.b    .goide
  3160.         lea.l    .noide_txt(pc),a0
  3161.         bsr    print
  3162.         bra.w    end_disk
  3163. .goide        tst.b    config_elsat
  3164.         beq.b    .nocd32
  3165.         lea.l    .cd32_txt(pc),a0
  3166.         bsr    print
  3167.         bra.b    .cont
  3168. .nocd32        tst.b    config_A1200
  3169.         beq.b    .go4000
  3170.         lea.l    .a1200_txt(pc),a0
  3171.         bsr    print
  3172.         bra.b    .cont
  3173. .go4000        lea.l    .a4000_txt(pc),a0
  3174.         bsr    print
  3175.  
  3176. .cont        lea.l    secbuf,a0
  3177.         tst.w    IDE_info0
  3178.         beq.b    .nodrive0
  3179.         moveq    #0,d1        ;drive no 0
  3180.         bsr    Read_ID
  3181.         bne.b    .nodrive0
  3182.         lea.l    ide1_txt(pc),a0
  3183.         bsr    print
  3184.         bsr    .print_info
  3185.         bra.b    .okdrive0
  3186. .nodrive0    lea.l    ide2_txt(pc),a0
  3187.         bsr    print
  3188.  
  3189. .okdrive0    lea.l    secbuf,a0
  3190.         tst.w    IDE_info1
  3191.         beq.b    .nodrive1
  3192.         moveq    #1,d1        ;drive no 1
  3193.         bsr    Read_ID
  3194.         bne.b    .nodrive1
  3195.         lea.l    ide3_txt(pc),a0
  3196.         bsr    print
  3197.         bsr    .print_info
  3198.         bra.b    .okdrive1
  3199. .nodrive1    lea.l    ide4_txt(pc),a0
  3200.         bsr    print
  3201.  
  3202. .okdrive1    moveq    #0,d0
  3203.         moveq    #0,d1
  3204.         tst.w    IDE_info0
  3205.         beq.b    .no0
  3206.         lea.l    secbuf,a0
  3207.         bsr    Read_Block
  3208. .no0
  3209.         bra.w    end_disk
  3210.  
  3211. .noide_txt    dc.b "No IDE interface",$a,0
  3212. .cd32_txt    dc.b "ELSAT CD32 Pro Module IDE interface",$a,0
  3213. .a1200_txt    dc.b "Gayle A1200 IDE interface",$a,0
  3214. .a4000_txt    dc.b "Gayle A4000 IDE interface",$a,0
  3215.         even
  3216.  
  3217. .print_info    lea.l    secbuf,a4
  3218.         lea.l    ide5_txt(pc),a0
  3219.         bsr    print
  3220.         lea.l    27*2(a4),a0
  3221.         move.w    #$0a00,46*2(a4)
  3222.         tst.w    (a0)
  3223.         bne.b    .okname
  3224.         lea.l    ide10_txt(pc),a0
  3225. .okname        bsr    print            ;name
  3226.  
  3227.         lea.l    ide6_txt(pc),a0
  3228.         bsr    print
  3229.         lea.l    10*2(a4),a0
  3230.         move.w    #$0a00,19*2(a4)
  3231.         tst.w    (a0)
  3232.         bne.b    .okser
  3233.         lea.l    ide10_txt(pc),a0
  3234. .okser        cmp.b    #$20,(a0)+
  3235.         beq.b    .okser
  3236.         subq.l    #1,a0
  3237.         move.l    a0,a1
  3238. .seeke        tst.b    (a1)+
  3239.         bne.b    .seeke
  3240.         move.b    #$a,-2(a1)
  3241.         bsr    print            ;serial
  3242.  
  3243.         lea.l    ide7_txt(pc),a0
  3244.         bsr    print
  3245.         move.w    1*2(a4),d0
  3246.         moveq    #4,d1
  3247.         bsr    print_decCR        ;cylinders
  3248.  
  3249.         lea.l    ide8_txt(pc),a0
  3250.         bsr    print
  3251.         move.w    3*2(a4),d0
  3252.         moveq    #4,d1
  3253.         bsr    print_decCR        ;heads
  3254.  
  3255.         lea.l    ide9_txt(pc),a0
  3256.         bsr    print
  3257.         move.w    6*2(a4),d0
  3258.         moveq    #4,d1
  3259.         bsr    print_decCR        ;sectors
  3260.  
  3261.         lea.l    ide11_txt(pc),a0
  3262.         bsr    print
  3263.         moveq    #5,d1
  3264.         move.w    3*2(a4),d0
  3265.         mulu    6*2(a4),d0        ;sec*heads
  3266.         mulu    1*2(a4),d0        ;cyl*sec*heads
  3267.         moveq    #11,d1
  3268.         lsr.l    d1,d0
  3269.         moveq    #4,d1
  3270.         bsr    print_dec
  3271.         lea.l    ide12_txt(pc),a0
  3272.         bsr    print
  3273.  
  3274.         rts
  3275.  
  3276. ide1_txt    dc.b "-- Drive 0   : present",$a,0
  3277. ide2_txt    dc.b "-- Drive 0   : absent",$a,0
  3278. ide3_txt    dc.b "-- Drive 1   : present",$a,0
  3279. ide4_txt    dc.b "-- Drive 1   : absent",$a,0
  3280. ide5_txt    dc.b "   Name      : ",0
  3281. ide6_txt    dc.b "   Serial no : ",0
  3282. ide7_txt    dc.b "   Cylinders : ",0
  3283. ide8_txt    dc.b "   Heads     : ",0
  3284. ide9_txt    dc.b "   Sectors   : ",0
  3285. ide10_txt    dc.b "N/A",$a,0
  3286. ide11_txt    dc.b "   Capacity  : ",0
  3287. ide12_txt    dc.b "(MB)",$a,0
  3288.         even
  3289.  
  3290. ;-------------- COPY --------------------------------------
  3291.  
  3292. cmd_copy
  3293.         lea.l    ev_line,a1
  3294.         bsr    read_name        ;get source name
  3295.         tst.b    (a1)
  3296.         beq.w    illegal_name
  3297.         lea.l    general_txt,a1
  3298.         bsr    read_name        ;get dest name
  3299.         tst.b    (a1)
  3300.         beq.w    illegal_name
  3301.  
  3302.         bsr    remove_pic
  3303.  
  3304.         moveq    #0,d6
  3305.         moveq    #0,d7
  3306.         move.l    #ev_line,d1
  3307.         moveq    #0,d2
  3308.         bsr    open_file
  3309.         move.l    d0,d6
  3310.         beq.w    .err
  3311.         move.l    #general_txt,d1
  3312.         moveq    #-1,d2
  3313.         bsr    open_file
  3314.         move.l    d0,d7
  3315.         bne.b    .okdest
  3316.  
  3317.         cmp.w    #FILEEXIST_ERR,drive_err
  3318.         bne.w    .err        ;got only path without filename ?
  3319.         clr.w    drive_err
  3320.         lea.l    general_txt,a0
  3321. .seek        tst.b    (a0)+
  3322.         bne.b    .seek
  3323.         subq.l    #1,a0
  3324.         cmp.b    #':',-1(a0)
  3325.         beq.b    .noslash
  3326.         move.b    #'/',(a0)+
  3327. .noslash    move.l    d6,a1
  3328.         lea.l    file_name(a1),a1
  3329.         moveq    #0,d0
  3330.         move.b    (a1)+,d0
  3331.         bra.b    .godbf
  3332. .addname    move.b    (a1)+,(a0)+    ;add filename to dest
  3333. .godbf        dbf    d0,.addname
  3334.         sf    (a0)
  3335.  
  3336.         move.l    #general_txt,d1
  3337.         moveq    #-1,d2
  3338.         bsr    open_file    ;retry with filename
  3339.         move.l    d0,d7
  3340.         beq.b    .err
  3341. .okdest
  3342.  
  3343.         move.l    d6,a0
  3344.         move.l    file_size(a0),d5
  3345.         beq.b    .err
  3346.  
  3347.         move.w    #-1,ts_size        ;trainer buffer cleared
  3348.  
  3349. .nextblock    move.l    #tmp_mem_size,d3
  3350.         cmp.l    d3,d5
  3351.         bge.b    .okd5
  3352.         move.l    d5,d3
  3353. .okd5        sub.l    d3,d5
  3354.  
  3355.         move.l    d6,d1
  3356.         move.l    #tmp_mem,d2
  3357.         bsr    read_file
  3358.         tst.l    d0
  3359.         bne.b    .err
  3360.  
  3361.         move.l    d7,d1
  3362.         bsr    write_file
  3363.         tst.l    d0
  3364.         bne.b    .err
  3365.  
  3366.         tst.l    d5
  3367.         bne.b    .nextblock
  3368.  
  3369. .err        move.l    d6,d1
  3370.         beq.b    .noclose1
  3371.         bsr    close_file
  3372. .noclose1    move.l    d7,d1
  3373.         beq.b    .noclose2
  3374.         bsr    close_file
  3375. .noclose2
  3376.         bsr    set_pic
  3377.  
  3378.         bra.w    end_disk
  3379.  
  3380. ;-------------- OUTPUT ------------------------------------
  3381.  
  3382. cmd_output    bsr    evaluate
  3383.         bne.b    .end
  3384.         tst.l    d0
  3385.         beq.b    .end
  3386.         move.l    d0,output_ptr
  3387.         move.l    d0,output_start
  3388. ;        move.l    d0,watch2
  3389.  
  3390.         bra.b    .out
  3391.  
  3392. .end        move.l    output_ptr,d2
  3393.         move.l    output_start,d0
  3394.         clr.l    output_ptr
  3395.         clr.l    output_start
  3396.  
  3397.         lea.l    endout_txt,a0
  3398.         bsr    print
  3399.         moveq    #8,d1
  3400.         bsr    print_hex        ;output_start
  3401.         lea.l    endout2_txt,a0
  3402.         bsr    print
  3403.         move.l    d2,d0            ;output_ptr
  3404.         bsr    print_hexCR
  3405.  
  3406. .out        bra.w    end_command
  3407.  
  3408. endout_txt    dc.b "Output memory from $",0
  3409. endout2_txt    dc.b " to $",0
  3410.         cnop 0,4
  3411.  
  3412. ;-------------- Q (compare memory) ------------------------
  3413.  
  3414. cmd_q        bsr    evaluate
  3415.         bne.w    illegal_addr
  3416.         move.l    d0,cmp_start
  3417.         bsr    evaluate
  3418.         bne.w    illegal_addr
  3419.         move.l    d0,cmp_end
  3420.         sub.l    cmp_start,d0
  3421.         ble.w    illegal_addr
  3422.         bsr    evaluate
  3423.         bne.w    illegal_addr
  3424.         move.l    d0,cmp_dest
  3425.  
  3426.         bsr    remove_pic
  3427.         moveq    #0,d0
  3428.         move.l    d0,$180(a6)
  3429.  
  3430.         move.l    cmp_start,a0
  3431.         move.l    cmp_dest,a1
  3432.         move.l    cmp_end,a2
  3433.         moveq    #-1,d0
  3434.  
  3435. .ok        cmp.l    a2,a0
  3436.         bge.b    .end_cmp
  3437.         cmpm.b    (a0)+,(a1)+
  3438.         beq.b    .ok
  3439.         move.l    a0,d0
  3440.         subq.l    #1,d0
  3441. .end_cmp
  3442.         bsr    set_pic
  3443.  
  3444.         moveq    #-1,d1
  3445.         cmp.l    d1,d0
  3446.         beq.b    .equal
  3447.  
  3448.         moveq    #8,d1
  3449.         bsr    print_hexCR
  3450.         bra.b    .out
  3451. .equal
  3452.         lea.l    equal_txt,a0
  3453.         bsr    print
  3454. .out
  3455.         bra.w    end_command
  3456.  
  3457. equal_txt    dc.b "Equal areas.",$a,0
  3458.         even
  3459.  
  3460. ;-------------- A -----------------------------------------
  3461.  
  3462. cmd_a        move.l    a0,a3
  3463.         bsr    evaluate
  3464.         bne.b    .godisas
  3465.         btst    #0,d0
  3466.         bne.w    illegal_addr
  3467.         move.l    d0,a1
  3468.         move.l    a1,ass_addr
  3469. .skip        cmp.b    #$20,(a0)+
  3470.         beq.b    .skip
  3471.         subq.l    #1,a0
  3472.         tst.b    (a0)
  3473.         bne.b    .goas
  3474. .godisas    move.l    a3,a0
  3475.         bra.w    cmd_d
  3476.  
  3477. .goas        jsr    assemble
  3478.         tst.l    d0
  3479.         bne.w    illegal_syntax
  3480.  
  3481. .ok        lea.l    op68000,a0
  3482.         move.l    ass_addr,a4
  3483.         bsr    corr_addr
  3484.         move.w    oplen,d0
  3485. .copy        move.w    (a0)+,(a4)+
  3486.         dbf    d0,.copy
  3487.  
  3488.         moveq    #8,d1
  3489.         move.l    ass_addr,d0
  3490.         moveq    #0,d2
  3491.         move.w    oplen,d2
  3492.         add.w    d2,d2
  3493.         addq.l    #2,d2
  3494.         add.l    d2,d0
  3495.  
  3496.         lea.l    new_ass(pc),a0
  3497.         bsr    print
  3498.         bsr    print_hex
  3499.         lea.l    new_ass2(pc),a0
  3500.         bsr    print
  3501.         bra.w    end_command
  3502.  
  3503. new_ass        dc.b "a $",0
  3504. new_ass2    dc.b " ",0
  3505.         cnop 0,4
  3506.  
  3507. ;-------------- O -----------------------------------------
  3508. ;fill memory
  3509. cmd_o        bsr    evaluate
  3510.         bne.w    illegal_addr
  3511.         move.l    d0,fill_start
  3512.         move.l    d0,d1
  3513.         bsr    evaluate
  3514.         bne.w    illegal_addr
  3515.         move.l    d0,fill_end
  3516.         sub.l    d1,d0
  3517.         ble.w    illegal_addr
  3518.  
  3519.         clr.w    eval_size        ;.b par default
  3520.         bsr    evaluate
  3521.  
  3522.         bsr    remove_pic
  3523.         movem.l    fill_start,a0-a1
  3524.         move.w    eval_size,d1
  3525.         cmp.w    #3,d1
  3526.         beq.b    .fillL
  3527.         cmp.w    #1,d1
  3528.         beq.b    .fillW
  3529. .fillb        move.b    d0,(a0)+
  3530.         cmp.l    a1,a0
  3531.         blt.b    .fillb
  3532.         bra.b    .out
  3533. .fillW        move.w    d0,(a0)+
  3534.         cmp.l    a1,a0
  3535.         blt.b    .fillW
  3536.         bra.b    .out
  3537. .fillL        move.l    d0,(a0)+
  3538.         cmp.l    a1,a0
  3539.         blt.b    .fillL
  3540.  
  3541.  
  3542. .out        bsr    set_pic
  3543.  
  3544.         bra.w    end_command
  3545.  
  3546. ;-------------- Switch led --------------------------------
  3547.  
  3548. cmd_led        bchg    #1,$bfe001
  3549.         bchg    #1,CIAA+0
  3550.         bra.w    end_command
  3551.  
  3552. ;-------------- PAL/NTSC ----------------------------------
  3553.  
  3554. cmd_pal        clr.l    OldRaster
  3555.         move.w    #$20,custom+$1dc
  3556.         bra.w    end_command
  3557. cmd_ntsc    clr.l    OldRaster
  3558.         move.w    #0,custom+$1dc
  3559.         bra.w    end_command
  3560.  
  3561. cmd_31k        clr.l    OldRaster
  3562.         move.w    #$3a0,custom+$1dc
  3563.         bra.w    end_command
  3564.  
  3565. ;-------------- S (SAVEFILE) ------------------------------
  3566.  
  3567. cmd_s
  3568.         lea.l    ev_line,a1
  3569.         bsr.w    read_name
  3570.         tst.b    (a1)
  3571.         beq.w    illegal_name
  3572.         bsr    evaluate
  3573.         bne.w    illegal_addr
  3574.         bne.w    illegal_addr
  3575.         move.l    d0,d4            ;d4=save start
  3576.         bsr    evaluate
  3577.         bne.w    illegal_addr
  3578.         bne.w    illegal_addr
  3579.         move.l    d0,d3            ;d3=save end
  3580.         move.l    d0,d1
  3581.         move.l    d4,d0
  3582.         sub.l    d4,d3            ;d3=save len
  3583.         ble.w    illegal_addr        ;end must be > start
  3584.  
  3585.         bsr    remove_pic
  3586.  
  3587.         move.l    #ev_line,d1        ;ptr on filename
  3588.         moveq    #-1,d2            ;mode create
  3589.         bsr    open_file
  3590.         move.l    d0,d7
  3591.         beq.b    .err
  3592.  
  3593.         move.l    d4,d2
  3594.         move.l    d7,d1
  3595.         bsr    write_file        ;save mem
  3596.  
  3597.         move.l    d7,d1
  3598.         bsr    close_file
  3599.  
  3600. .err        bsr    set_pic
  3601.  
  3602.         bra.w    end_disk
  3603.  
  3604.  
  3605. ;-------------- MAKEDIR -----------------------------------
  3606.  
  3607. cmd_makedir    lea.l    ev_line,a1
  3608.         bsr.w    read_name
  3609.         tst.b    (a1)
  3610.         beq.w    illegal_name
  3611.  
  3612.         move.l    #ev_line,d1
  3613.         bsr    create_dir
  3614.  
  3615.         bra.w    end_disk
  3616.  
  3617. ;-------------- SA ----------------------------------------
  3618. ;-------------- save the actual state in a file -----------
  3619.  
  3620. cmd_sa
  3621.         lea.l    ev_line,a1
  3622.         bsr.w    read_name
  3623.         tst.b    (a1)
  3624.         beq.w    illegal_name
  3625.  
  3626.         sub.l    a0,a0
  3627.         move.l    max_chip,a1
  3628.         bsr    search_cop
  3629.  
  3630.         move.w    drive,-(a7)
  3631.         moveq    #3,d4            ;first drive SEL (drive0)
  3632.         lea.l    drive_present,a3
  3633.         moveq    #4-1,d5            ;4 drives
  3634. .loopd        tst.b    (a3)+
  3635.         beq.b    .nodrive
  3636.         move.w    d4,drive        ;get
  3637.         bsr    inittete        ;floppy drive head pos
  3638. .nodrive    addq.w    #1,d4
  3639.         dbf    d5,.loopd
  3640.         move.w    (a7)+,drive
  3641.  
  3642.         bsr    remove_pic
  3643.  
  3644.         move.l    #ev_line,d1        ;ptr on filename
  3645.         moveq    #-1,d2            ;mode create
  3646.         bsr    open_file
  3647.         move.l    d0,d7
  3648.         beq.w    .err
  3649.  
  3650.         move.w    #-1,ts_size        ;trainer buffer cleared
  3651.  
  3652.         lea.l    tmp_mem,a4
  3653.         move.l    #"ARSV",(a4)
  3654.  
  3655.         move.l    d7,d1
  3656.         move.l    a4,d2
  3657.         moveq    #4,d3
  3658.         bsr    write_file        ;save header 'ARSV'
  3659.         bne.w    .err
  3660.  
  3661.         move.l    d7,d1
  3662.         move.l    #registres,d2
  3663.         move.l    #end_registres-registres,d3
  3664.         bsr    write_file        ;save registers
  3665.         bne.w    .err
  3666.  
  3667.         move.l    d7,d1
  3668.         move.l    #custom,d2
  3669.         move.l    #$200,d3
  3670.         bsr    write_file        ;save custom registers
  3671.         bne.w    .err
  3672.  
  3673.         move.l    d7,d1
  3674.         move.l    #palette,d2
  3675.         move.l    #256*4,d3
  3676.         bsr    write_file        ;save palette
  3677.         bne.w    .err
  3678.  
  3679.         move.l    d7,d1
  3680.         move.l    #CIAA,d2
  3681.         moveq    #32,d3
  3682.         bsr    write_file        ;save CIA registers
  3683.         bne.w    .err
  3684.  
  3685.         move.l    d7,d1
  3686.         move.l    #old_head,d2
  3687.         moveq    #4*2,d3
  3688.         bsr    write_file        ;write head pos of drives
  3689.         bne.w    .err
  3690.  
  3691.         move.l    d7,a0
  3692.         move.l    file_part(a0),a0
  3693.         cmp.l    #floppy_device,part_device(a0)
  3694.         bne.w    .goHD
  3695.  
  3696. ;-------------- floppy save routine ----------------
  3697.         move.l    d7,d1
  3698.         moveq    #0,d2
  3699.         move.l    #$CD000,d3
  3700.         bsr    write_file        ;write data on Disk1
  3701.         bne.w    .err
  3702.         move.l    d7,d1
  3703.         bsr    close_file
  3704.  
  3705.         bsr    flush_fbuffer
  3706.         bsr    force_change
  3707.  
  3708.         bsr    set_pic
  3709.         lea.l    disk2_txt(pc),a0
  3710.         bsr    print
  3711.         bsr    get_key
  3712.         lea.l    diskclr_txt(pc),a0
  3713.         bsr    print
  3714.         bsr    remove_pic
  3715.         tst.b    break
  3716.         bne.w    .err
  3717.  
  3718.         move.l    #ev_line,d1        ;ptr on filename
  3719.         moveq    #-1,d2            ;mode create
  3720.         bsr    open_file
  3721.         move.l    d0,d7
  3722.         beq.w    .err
  3723.  
  3724.         lea.l    tmp_mem,a4
  3725.         move.l    #"ARS2",(a4)
  3726.         move.l    d7,d1
  3727.         move.l    a4,d2
  3728.         moveq    #4,d3
  3729.         bsr    write_file
  3730.         bne.w    .err
  3731.  
  3732.         move.l    d7,d1
  3733.         move.l    #$CD000,d2
  3734.         move.l    d2,d3
  3735.         bsr    write_file        ;write data on Disk2
  3736.         bne.w    .err
  3737.         move.l    d7,d1
  3738.         bsr    close_file
  3739.  
  3740.         bsr    flush_fbuffer
  3741.         bsr    force_change
  3742.  
  3743.         bsr    set_pic
  3744.         lea.l    disk3_txt(pc),a0
  3745.         bsr    print
  3746.         bsr    get_key
  3747.         lea.l    diskclr_txt(pc),a0
  3748.         bsr    print
  3749.         bsr    remove_pic
  3750.         tst.b    break
  3751.         bne.b    .err
  3752.  
  3753.         move.l    #ev_line,d1        ;ptr on filename
  3754.         moveq    #-1,d2            ;mode create
  3755.         bsr    open_file
  3756.         move.l    d0,d7
  3757.         beq.b    .err
  3758.  
  3759.         lea.l    tmp_mem,a4
  3760.         move.l    #"ARS3",(a4)
  3761.         move.l    d7,d1
  3762.         move.l    a4,d2
  3763.         moveq    #4,d3
  3764.         bsr    write_file
  3765.         bne.b    .err
  3766.  
  3767.         move.l    d7,d1
  3768.         move.l    #$CD000*2,d2
  3769.         move.l    #$200000-$CD000*2,d3
  3770.         bsr    write_file        ;write data on Disk3
  3771.         bne.b    .err
  3772.         bra.b    .endsave
  3773.  
  3774. .goHD        move.l    d7,d1
  3775.         moveq    #0,d2
  3776.         move.l    #$200000,d3
  3777.         bsr    write_file        ;save all CHIPMEM
  3778.         bne.b    .err
  3779.  
  3780. .endsave    move.l    d7,d1
  3781.         bsr    close_file
  3782.  
  3783. .err        bsr    set_pic
  3784.  
  3785.         bra.w    end_disk
  3786.  
  3787.  
  3788. disk1_txt    dc.b "Please insert disk 1 and press any key.",$d,0
  3789. disk2_txt    dc.b "Please insert disk 2 and press any key.",$d,0
  3790. disk3_txt    dc.b "Please insert disk 3 and press any key.",$d,0
  3791. diskclr_txt    dc.b "                                                   ",$d,0
  3792.         even
  3793.  
  3794.  
  3795. ;-------------- SAC ---------------------------------------
  3796. ;-------------- save the actual state in a file compressed
  3797.  
  3798. cmd_sac
  3799.         lea.l    ev_line,a1
  3800.         bsr.w    read_name
  3801.         tst.b    (a1)
  3802.         beq.w    illegal_name
  3803.  
  3804.         sub.l    a0,a0
  3805.         move.l    max_chip,a1
  3806.         bsr    search_cop
  3807.  
  3808.         move.w    drive,-(a7)
  3809.         moveq    #3,d4            ;first drive SEL (drive0)
  3810.         lea.l    drive_present,a3
  3811.         moveq    #4-1,d5            ;4 drives
  3812. .loopd        tst.b    (a3)+
  3813.         beq.b    .nodrive
  3814.         move.w    d4,drive        ;get
  3815.         bsr    inittete        ;floppy drive head pos
  3816. .nodrive    addq.w    #1,d4
  3817.         dbf    d5,.loopd
  3818.         move.w    (a7)+,drive
  3819.  
  3820.         bsr    remove_pic
  3821.  
  3822.         move.l    #ev_line,d1        ;ptr on filename
  3823.         moveq    #-1,d2            ;mode create
  3824.         bsr    open_file
  3825.         move.l    d0,d7
  3826.         beq.w    .err
  3827.  
  3828.         move.w    #-1,ts_size        ;trainer buffer cleared
  3829.  
  3830.         lea.l    tmp_mem,a4
  3831.         move.l    #"ARSC",(a4)
  3832.  
  3833.         move.l    d7,d1
  3834.         move.l    a4,d2
  3835.         moveq    #4,d3
  3836.         bsr    write_file        ;save header 'ARSC'
  3837.         bne.w    .err
  3838.  
  3839.         move.l    d7,d1
  3840.         move.l    #registres,d2
  3841.         move.l    #end_registres-registres,d3
  3842.         bsr    write_file        ;save registers
  3843.         bne.w    .err
  3844.  
  3845.         move.l    d7,d1
  3846.         move.l    #custom,d2
  3847.         move.l    #$200,d3
  3848.         bsr    write_file        ;save custom registers
  3849.         bne.w    .err
  3850.  
  3851.         move.l    d7,d1
  3852.         move.l    #palette,d2
  3853.         move.l    #256*4,d3
  3854.         bsr    write_file        ;save palette
  3855.         bne.w    .err
  3856.  
  3857.         move.l    d7,d1
  3858.         move.l    #CIAA,d2
  3859.         moveq    #32,d3
  3860.         bsr    write_file        ;save CIA registers
  3861.         bne.w    .err
  3862.  
  3863.         move.l    d7,d1
  3864.         move.l    #old_head,d2
  3865.         moveq    #4*2,d3
  3866.         bsr    write_file        ;write head pos of drives
  3867.         bne.w    .err
  3868.  
  3869.         move.l    d7,a0
  3870.         move.l    file_part(a0),a0
  3871.         cmp.l    #floppy_device,part_device(a0)
  3872.         bne.w    .goHD
  3873.  
  3874. ;-------------- floppy save routine ----------------
  3875.  
  3876.         move.l    d7,d1
  3877.         moveq    #0,d2
  3878.         move.l    #$4008,d3
  3879.         bsr    write_file        ;write low-mem
  3880.         bne.w    .err
  3881.  
  3882.         lea.l    $4008.w,a0
  3883.         sub.l    a1,a1
  3884.         move.l    #$200000-$4008,d0
  3885.         bsr    pack
  3886.         move.l    d0,d6            ;d6=packed size
  3887.  
  3888.         move.l    d6,d3
  3889.         move.l    #1730*512-$4008-$68e,d0    ;size left on disk
  3890.         cmp.l    d0,d3
  3891.         blt.b    .okd3
  3892.         move.l    d0,d3
  3893. .okd3        sub.l    d3,d6
  3894.         move.l    d7,d1
  3895.         moveq    #0,d2
  3896.         bsr    write_file        ;write data on 1st disk
  3897.         bne.w    .err
  3898.  
  3899.         move.l    d7,d1
  3900.         bsr    close_file
  3901.  
  3902.         tst.l    d6
  3903.         beq.w    .lowmem
  3904.  
  3905. ;----------
  3906.  
  3907.         bsr    flush_fbuffer
  3908.         bsr    force_change
  3909.  
  3910.         bsr    set_pic
  3911.         lea.l    disk2_txt(pc),a0
  3912.         bsr    print
  3913.         bsr    get_key
  3914.         lea.l    diskclr_txt(pc),a0
  3915.         bsr    print
  3916.         bsr    remove_pic
  3917.         tst.b    break
  3918.         bne.w    .err
  3919.  
  3920.         move.l    #ev_line,d1        ;ptr on filename
  3921.         moveq    #-1,d2            ;mode create
  3922.         bsr    open_file
  3923.         move.l    d0,d7
  3924.         beq.w    .err
  3925.  
  3926.         lea.l    tmp_mem,a4
  3927.         move.l    #"ARC2",(a4)
  3928.         move.l    d7,d1
  3929.         move.l    a4,d2
  3930.         moveq    #4,d3
  3931.         bsr    write_file
  3932.         bne.w    .err
  3933.  
  3934.         move.l    d6,d3
  3935.         move.l    #1730*512-4,d0
  3936.         cmp.l    d0,d3
  3937.         blt.b    .okd3b
  3938.         move.l    d0,d3
  3939. .okd3b        sub.l    d3,d6
  3940.         move.l    d7,d1
  3941.         move.l    #1730*512-$4008-$68e,d2    ;size saved on 1st disk
  3942.         bsr    write_file
  3943.         bne.w    .err
  3944.  
  3945.         move.l    d7,d1
  3946.         bsr    close_file
  3947.         tst.l    d6
  3948.         beq.w    .enddisk
  3949.  
  3950. ;----------
  3951.  
  3952.         bsr    flush_fbuffer
  3953.         bsr    force_change
  3954.  
  3955.         bsr    set_pic
  3956.         lea.l    disk3_txt(pc),a0
  3957.         bsr    print
  3958.         bsr    get_key
  3959.         lea.l    diskclr_txt(pc),a0
  3960.         bsr    print
  3961.         bsr    remove_pic
  3962.         tst.b    break
  3963.         bne.w    .err
  3964.  
  3965.         move.l    #ev_line,d1        ;ptr on filename
  3966.         moveq    #-1,d2            ;mode create
  3967.         bsr    open_file
  3968.         move.l    d0,d7
  3969.         beq.w    .err
  3970.  
  3971.         lea.l    tmp_mem,a4
  3972.         move.l    #"ARC3",(a4)
  3973.         move.l    d7,d1
  3974.         move.l    a4,d2
  3975.         moveq    #4,d3
  3976.         bsr    write_file
  3977.         bne.w    .err
  3978.  
  3979.         move.l    d6,d3
  3980.         move.l    d7,d1
  3981.         move.l    #(1730*512-$4008-$68e)+(1730*512-4),d2
  3982.                         ;size saved on disks 1&2
  3983.         bsr    write_file
  3984.         bne.w    .err
  3985.  
  3986. .retry        move.l    d7,d1
  3987.         bsr    close_file
  3988.  
  3989. .enddisk    bsr    flush_fbuffer
  3990.         bsr    force_change
  3991.         clr.w    drive_err
  3992.  
  3993.         bsr    set_pic
  3994.         lea.l    disk1_txt(pc),a0
  3995.         bsr    print
  3996.         bsr    get_key
  3997.         lea.l    diskclr_txt(pc),a0
  3998.         bsr    print
  3999.         bsr    remove_pic
  4000.         tst.b    break
  4001.         bne.w    .err
  4002.  
  4003. .lowmem        move.l    #ev_line,d1
  4004.         moveq    #0,d2
  4005.         bsr    open_file
  4006.         move.l    d0,d7
  4007.         beq.b    .enddisk
  4008.  
  4009.         lea.l    tmp_mem,a4
  4010.         move.l    a4,d2
  4011.         moveq    #4,d3
  4012.         move.l    d7,d1
  4013.         bsr    read_file
  4014.         bne.b    .retry
  4015.         cmp.l    #"ARSC",(a4)
  4016.         bne.b    .retry
  4017.  
  4018.         move.l    d7,d1
  4019.         move.l    #$68e,d2
  4020.         moveq    #-1,d3
  4021.         bsr    seek_file
  4022.  
  4023.         sub.l    a0,a0
  4024.         lea.l    $4008.w,a1
  4025.         bsr    depack
  4026.  
  4027.         move.l    d7,d1
  4028.         moveq    #0,d2
  4029.         move.l    #$4008,d3
  4030.         bsr    read_file
  4031.  
  4032.         bra.b    .endsave
  4033.  
  4034. ;-----------------------------------------------
  4035.  
  4036. .goHD        move.l    d7,d1
  4037.         moveq    #0,d2
  4038.         move.l    #$4008,d3
  4039.         bsr    write_file        ;save low-mem
  4040.         bne.b    .err
  4041.  
  4042.         lea.l    $4008.w,a0
  4043.         lea.l    $0.w,a1
  4044.         move.l    #$200000-$4008,d0
  4045.         bsr    pack
  4046.         move.l    d0,d3
  4047.         move.l    d0,d5            ;d5=packed size+header
  4048.         move.l    d7,d1
  4049.         moveq    #0,d2
  4050.         bsr    write_file        ;save packed mem
  4051.         bne.b    .err
  4052.  
  4053.         lea.l    $0.w,a0
  4054.         lea.l    $4008.w,a1
  4055.         bsr    depack
  4056.  
  4057.         move.l    d7,d1
  4058.         move.l    d5,d2
  4059.         add.l    #$4008,d2
  4060.         neg.l    d2
  4061.         moveq    #0,d3
  4062.         bsr    seek_file
  4063.  
  4064.         move.l    d7,d1
  4065.         moveq    #0,d2
  4066.         move.l    #$4008,d3
  4067.         bsr    read_file
  4068.  
  4069. .endsave    move.l    d7,d1
  4070.         bsr    close_file
  4071.  
  4072. .err        bsr    set_pic
  4073.  
  4074.         bra.w    end_disk
  4075.  
  4076.  
  4077. ;-------------- LA ----------------------------------------
  4078. ;-------------- load a saved game -------------------------
  4079.  
  4080. cmd_la        lea.l    ev_line,a1
  4081.         bsr.w    read_name
  4082.         tst.b    (a1)
  4083.         beq.w    illegal_name
  4084.  
  4085.         bsr    remove_pic
  4086.  
  4087.         move.l    #ev_line,d1        ;ptr on filename
  4088.         moveq    #0,d2            ;mode oldfile
  4089.         bsr    open_file
  4090.         move.l    d0,d7
  4091.         beq.w    .err
  4092.  
  4093.         lea.l    tmp_mem,a4
  4094.  
  4095.         move.w    #-1,ts_size        ;trainer buffer cleared
  4096.  
  4097.         move.l    d7,d1
  4098.         move.l    a4,d2
  4099.         moveq    #4,d3
  4100.         bsr    read_file        ;read header 'ARSV'
  4101.         bne.w    .err
  4102.  
  4103.         sf    packed
  4104.         cmp.l    #'ARSV',(a4)
  4105.         beq.b    .okarsv
  4106.         st    packed
  4107.         cmp.l    #'ARSC',(a4)
  4108.         beq.b    .okarsv
  4109.         lea.l    noarsv_txt(pc),a0
  4110.         bsr    print
  4111.         bra.w    .close
  4112. .okarsv
  4113.         move.l    d7,d1
  4114.         move.l    #registres,d2
  4115.         move.l    #end_registres-registres,d3
  4116.         bsr    read_file        ;read registers
  4117.         bne.w    .err
  4118.  
  4119.         move.l    d7,d1
  4120.         move.l    #custom,d2
  4121.         move.l    #$200,d3
  4122.         bsr    read_file        ;read custom registers
  4123.         bne.w    .err
  4124.  
  4125.         lea.l    custom,a1
  4126.         lea.l    $dff000,a2
  4127.         lea.l    move_list2(pc),a0
  4128.         move.w    #$100-1,d0
  4129. .loop        tst.b    (a0)+
  4130.         beq.b    .nomove
  4131.         move.w    (a1),(a2)        ;reinit custom registers
  4132. .nomove        addq.l    #2,a1
  4133.         addq.l    #2,a2
  4134.         dbf    d0,.loop
  4135.         clr.w    $dff088
  4136.         move.w    #0,$dff106
  4137.         move.w    #0,$dff180
  4138.  
  4139.         move.l    d7,d1
  4140.         move.l    #palette,d2
  4141.         move.l    #256*4,d3
  4142.         bsr    read_file        ;read palette
  4143.         bne.w    .err
  4144.  
  4145.         move.l    d7,d1
  4146.         move.l    #CIAA,d2
  4147.         moveq    #32,d3
  4148.         bsr    read_file        ;read CIA registers
  4149.         bne.w    .err
  4150.  
  4151.         move.l    d7,d1
  4152.         move.l    a4,d2
  4153.         moveq    #8,d3
  4154.         bsr    read_file        ;read drive headpos
  4155.  
  4156.         lea.l    old_head,a1
  4157.         move.l    a4,a2
  4158.         move.w    drive,-(a7)
  4159.         moveq    #3,d4            ;first drive SEL (drive0)
  4160.         lea.l    drive_present,a3
  4161.         moveq    #4-1,d5            ;4 drives
  4162. .loopd        tst.b    (a3)+
  4163.         beq.b    .nodrive
  4164.         move.w    d4,drive        ;init
  4165.         bsr    inittete        ;floppy drive head pos
  4166.         move.w    (a2),(a1)        ;init old_head
  4167. .nodrive    addq.w    #1,d4
  4168.         addq.l    #2,a1
  4169.         addq.l    #2,a2
  4170.         dbf    d5,.loopd
  4171.         move.w    (a7)+,drive
  4172.  
  4173.         move.l    d7,a0
  4174.         move.l    file_part(a0),a0
  4175.         cmp.l    #floppy_device,part_device(a0)
  4176.         bne.w    .goHD
  4177.  
  4178. ;-------------- floppy load --------------------
  4179.  
  4180.         tst.b    packed
  4181.         beq.w    .nopackedf
  4182.  
  4183. ;-------------- packed floppy load ---------
  4184.  
  4185.         move.l    d7,d1
  4186.         move.l    #$4008,d2
  4187.         moveq    #0,d3
  4188.         bsr    seek_file        ;skip low-mem
  4189.  
  4190.         move.l    d7,d1
  4191.         moveq    #0,d2
  4192.         move.l    #1730*512-$68e-$4008,d3
  4193.         bsr    read_file        ;read 1st disk
  4194.  
  4195.         move.l    $0.w,d6
  4196.         bpl.b    .okposf
  4197.         neg.l    d6
  4198. .okposf        addq.l    #8,d6        ;d6=packed size
  4199.         move.l    d1,a0
  4200.         move.l    file_size(a0),d0
  4201.         sub.l    #$68e+$4008,d0
  4202.         move.l    d0,d5
  4203.         sub.l    d0,d6
  4204.         beq.w    .lowmem
  4205.  
  4206. .retry2c    move.l    d7,d1
  4207.         bsr    close_file
  4208.  
  4209. .retry2bc    bsr    set_pic
  4210.         lea.l    disk2_txt(pc),a0
  4211.         bsr    print
  4212.         bsr    get_key
  4213.         lea.l    diskclr_txt(pc),a0
  4214.         bsr    print
  4215.         bsr    remove_pic
  4216.         tst.b    break
  4217.         bne.w    .err
  4218.  
  4219.         clr.w    drive_err
  4220.         move.l    #ev_line,d1        ;ptr on filename
  4221.         moveq    #0,d2            ;mode oldfile
  4222.         bsr    open_file
  4223.         move.l    d0,d7
  4224.         beq.b    .retry2bc
  4225.  
  4226.         lea.l    tmp_mem,a4
  4227.         move.l    d7,d1
  4228.         move.l    a4,d2
  4229.         moveq    #4,d3
  4230.         bsr    read_file
  4231.         bne.b    .retry2c
  4232.         cmp.l    #"ARC2",(a4)
  4233.         bne.b    .retry2c
  4234.  
  4235.         move.l    d7,d1
  4236.         move.l    d5,d2
  4237.         move.l    #1730*512-4,d3
  4238.         bsr    read_file        ;read disk2
  4239.  
  4240.         move.l    d1,a0
  4241.         move.l    file_size(a0),d0
  4242.         subq.l    #4,d0
  4243.         sub.l    d0,d6
  4244.         beq.b    .enddisk
  4245.         add.l    d0,d5
  4246.  
  4247. .retry3c    move.l    d7,d1
  4248.         bsr    close_file
  4249.  
  4250. .retry3bc    bsr    set_pic
  4251.         lea.l    disk3_txt(pc),a0
  4252.         bsr    print
  4253.         bsr    get_key
  4254.         lea.l    diskclr_txt(pc),a0
  4255.         bsr    print
  4256.         bsr    remove_pic
  4257.         tst.b    break
  4258.         bne.w    .err
  4259.  
  4260.         clr.w    drive_err
  4261.         move.l    #ev_line,d1        ;ptr on filename
  4262.         moveq    #0,d2            ;mode oldfile
  4263.         bsr    open_file
  4264.         move.l    d0,d7
  4265.         beq.b    .retry3bc
  4266.  
  4267.         lea.l    tmp_mem,a4
  4268.         move.l    d7,d1
  4269.         move.l    a4,d2
  4270.         moveq    #4,d3
  4271.         bsr    read_file
  4272.         bne.b    .retry3c
  4273.         cmp.l    #"ARC3",(a4)
  4274.         bne.b    .retry3c
  4275.  
  4276.         move.l    d7,d1
  4277.         move.l    d5,d2
  4278.         move.l    #1730*512-4,d3
  4279.         bsr    read_file        ;read disk3
  4280.  
  4281. .enddisk
  4282.         move.l    d7,d1
  4283.         bsr    close_file
  4284.  
  4285.     ;ask disk1 and read low-mem
  4286.  
  4287. .retry1        bsr    set_pic
  4288.         lea.l    disk1_txt(pc),a0
  4289.         bsr    print
  4290.         bsr    get_key
  4291.         lea.l    diskclr_txt(pc),a0
  4292.         bsr    print
  4293.         bsr    remove_pic
  4294.         tst.b    break
  4295.         bne.w    .err
  4296.  
  4297.         clr.w    drive_err
  4298.         move.l    #ev_line,d1        ;ptr on filename
  4299.         moveq    #0,d2            ;mode oldfile
  4300.         bsr    open_file
  4301.         move.l    d0,d7
  4302.         beq.b    .retry1
  4303.  
  4304.         lea.l    tmp_mem,a4
  4305.         move.l    d7,d1
  4306.         move.l    a4,d2
  4307.         moveq    #4,d3
  4308.         bsr    read_file
  4309.         bne.b    .enddisk
  4310.         cmp.l    #"ARSC",(a4)
  4311.         bne.b    .enddisk
  4312.  
  4313. .lowmem        move.l    d7,d1
  4314.         move.l    #$68e,d2
  4315.         moveq    #-1,d3
  4316.         bsr    seek_file
  4317.  
  4318.         sub.l    a0,a0
  4319.         lea.l    $4008.w,a1
  4320.         bsr    depack
  4321.  
  4322.         move.l    d7,d1
  4323.         moveq    #0,d2
  4324.         move.l    #$4008,d3
  4325.         bsr    read_file        ;read low-mem
  4326.  
  4327.         bra.w    .close
  4328.  
  4329. ;-------------- non-packed floppy load -----
  4330.  
  4331. .nopackedf    move.l    d7,d1
  4332.         moveq    #0,d2
  4333.         move.l    #$CD000,d3
  4334.         bsr    read_file
  4335.         bne.w    .err
  4336.  
  4337. .retry2        move.l    d7,d1
  4338.         bsr    close_file
  4339.  
  4340. .retry2b    bsr    set_pic
  4341.         lea.l    disk2_txt(pc),a0
  4342.         bsr    print
  4343.         bsr    get_key
  4344.         lea.l    diskclr_txt(pc),a0
  4345.         bsr    print
  4346.         bsr    remove_pic
  4347.         tst.b    break
  4348.         bne.w    .err
  4349.  
  4350.         clr.w    drive_err
  4351.         move.l    #ev_line,d1        ;ptr on filename
  4352.         moveq    #0,d2            ;mode oldfile
  4353.         bsr    open_file
  4354.         move.l    d0,d7
  4355.         beq.b    .retry2b
  4356.  
  4357.         lea.l    tmp_mem,a4
  4358.         move.l    d7,d1
  4359.         move.l    a4,d2
  4360.         moveq    #4,d3
  4361.         bsr    read_file
  4362.         bne.b    .retry2
  4363.         cmp.l    #"ARS2",(a4)
  4364.         bne.b    .retry2
  4365.  
  4366.         move.l    d7,d1
  4367.         move.l    #$CD000,d2
  4368.         move.l    d2,d3
  4369.         bsr    read_file        ;read data from disk2
  4370.         bne.w    .err
  4371.  
  4372. .retry3        move.l    d7,d1
  4373.         bsr    close_file
  4374.  
  4375. .retry3b    bsr    set_pic
  4376.         lea.l    disk3_txt(pc),a0
  4377.         bsr    print
  4378.         bsr    get_key
  4379.         lea.l    diskclr_txt(pc),a0
  4380.         bsr    print
  4381.         bsr    remove_pic
  4382.         tst.b    break
  4383.         bne.w    .err
  4384.  
  4385.         clr.w    drive_err
  4386.         move.l    #ev_line,d1        ;ptr on filename
  4387.         moveq    #0,d2            ;mode oldfile
  4388.         bsr    open_file
  4389.         move.l    d0,d7
  4390.         beq.b    .retry3b
  4391.  
  4392.         lea.l    tmp_mem,a4
  4393.         move.l    d7,d1
  4394.         move.l    a4,d2
  4395.         moveq    #4,d3
  4396.         bsr    read_file
  4397.         bne.b    .retry3
  4398.         cmp.l    #"ARS3",(a4)
  4399.         bne.b    .retry3
  4400.  
  4401.         move.l    d7,d1
  4402.         move.l    #2*$CD000,d2
  4403.         move.l    #$200000-2*$CD000,d3
  4404.         bsr    read_file        ;read data from disk3
  4405.         bne.w    .err
  4406.         bra.w    .close
  4407.  
  4408. ;------------------------------------------------
  4409.  
  4410. .goHD        tst.b    packed
  4411.         beq.b    .nopacked
  4412.         move.l    d7,d1
  4413.         move.l    #$4008,d2
  4414.         moveq    #0,d3
  4415.         bsr    seek_file        ;skip low-mem
  4416.         move.l    d7,d1
  4417.         moveq    #0,d2
  4418.         moveq    #8,d3
  4419.         bsr    read_file        ;read pack header
  4420.         bne.b    .err
  4421.         move.l    $0.w,d3            ;get packed size
  4422.         bpl.b    .okpos
  4423.         neg.l    d3
  4424. .okpos        move.l    d7,d1
  4425.         moveq    #8,d2
  4426.         move.l    d3,d5
  4427.         bsr    read_file        ;read packed data
  4428.         lea.l    $0.w,a0
  4429.         lea.l    $4008.w,a1
  4430.         bsr    depack
  4431.  
  4432.         move.l    d7,d1
  4433.         move.l    d5,d2
  4434.         add.l    #$4008+8,d2
  4435.         neg.l    d2
  4436.         moveq    #0,d3
  4437.         bsr    seek_file
  4438.  
  4439.         move.l    d7,d1
  4440.         moveq    #0,d2
  4441.         move.l    #$4008,d3
  4442.         bsr    read_file        ;read low-mem area
  4443.  
  4444.         bra.b    .close
  4445.  
  4446. .nopacked    move.l    d7,d1
  4447.         moveq    #0,d2
  4448.         move.l    #$200000,d3
  4449.         bsr    read_file        ;read all CHIPMEM
  4450.         bne.b    .err
  4451.  
  4452. .close        move.l    d7,d1
  4453.         bsr    close_file
  4454.  
  4455. .err        bsr    set_pic
  4456.  
  4457.         bra.w    end_disk
  4458.  
  4459. noarsv_txt    dc.b "Not a HRTmon save file !",$a,0
  4460.         even
  4461.  
  4462. ;-------------- list of registers to be initialised after la_cmd ----
  4463.  
  4464. move_list2    dcb.b $10,0        ;$00-$1e
  4465.         dc.b -1,-1,-1        ;$20-$24
  4466.         dc.b 0,0,0,0        ;$26-$2c
  4467.         dcb.b 5,-1        ;$2e-$36
  4468.         dcb.b 4,0        ;$38-$3e
  4469.         dcb.b $c,-1        ;$40-$56
  4470.         dc.b 0,0        ;$58,$5a
  4471.         dc.b 0,0        ;$5c,$5e
  4472.         dcb.b 4,-1        ;$60-$66
  4473.         dcb.b 4,0        ;$68-$6e
  4474.         dc.b -1,-1,-1        ;$70-$74
  4475.         dcb.b 4,0        ;$76-$7c
  4476.         dc.b -1            ;$7e
  4477.         dc.b -1,-1        ;$80,$82    ;cop1
  4478.         dc.b -1,-1        ;$84,$86    ;cop2
  4479.         dc.b 0,0,0        ;$88,$8a,$8c
  4480.         dc.b -1,-1,-1,-1    ;$8e,$90,$92,$94
  4481.         dc.b 0,-1,0,0        ;$96-$9c
  4482.         dcb.b $21,-1        ;$9e-$de
  4483.         dcb.b $10,-1        ;$e0-$fe
  4484.         dc.b 0,0,-1,0        ;$100-$106
  4485.         dc.b -1,-1,0        ;$108-$10c
  4486.         dc.b -1            ;$10e
  4487.         dcb.b 8,0        ;$110-$11e
  4488.         dcb.b $10,-1        ;$120-$13e
  4489.         dcb.b $20,0        ;$140-$17e
  4490.         dcb.b $20,0        ;$180-$1be
  4491.         dcb.b $d,-1        ;$1c0-$1d8
  4492.         dc.b 0            ;$1da
  4493.         dc.b 0            ;$1dc
  4494.         dc.b -1,-1,-1        ;$1de-$1e2
  4495.         dc.b 0            ;$1e4
  4496.         dcb.b 5,-1        ;$1e6-$1ee
  4497.         dcb.b 6,0        ;$1f0-$1fa
  4498.         dc.b 0            ;$1fc
  4499.         dc.b 0            ;$1fe
  4500.  
  4501. ;-------------- MOTOR -------------------------------------
  4502.  
  4503. cmd_motor    bsr    motor_on
  4504.         bra.w    end_command
  4505.  
  4506. ;----------------------------------------------------------
  4507.  
  4508. cmd_intel    lea.l    outside_txt(pc),a0
  4509.         bsr    print
  4510.  
  4511.         lea.l    cheat_cnt,a0
  4512.         tst.b    (a0)
  4513.         beq.b    .zero
  4514.         sf    (a0)
  4515.         bra.b    .out
  4516. .zero        addq.b    #1,(a0)
  4517. .out        bra.w    end_command
  4518.  
  4519. outside_txt    dc.b "OUTSIDE !",$a,0
  4520.         even
  4521.  
  4522. cmd_hornet    lea.l    hornet_txt(pc),a0
  4523.         bsr    print
  4524.  
  4525.         lea.l    cheat_cnt,a0
  4526.         cmp.b    #1,(a0)
  4527.         beq.b    .zero
  4528.         sf    (a0)
  4529.         bra.b    .out
  4530. .zero        addq.b    #1,(a0)
  4531. .out        bra.w    end_command
  4532.  
  4533.  
  4534. hornet_txt    dc.b "Illegal but nice command.",$a,0
  4535.         even
  4536.  
  4537. ;-------------- TSD deep trainer start --------------------
  4538.  
  4539. cmd_tsd        st    ts_deep
  4540.         bra.b    cmd_ts_go
  4541.  
  4542. ;-------------- TS trainer start --------------------------
  4543.  
  4544. cmd_ts        sf    ts_deep
  4545.  
  4546. cmd_ts_go    bsr    evaluate        ;get start address
  4547.         bne.w    illegal_addr
  4548.         move.l    d0,ts_start
  4549.         bsr    evaluate        ;get end address
  4550.         bne.w    illegal_addr
  4551.         move.l    d0,ts_end
  4552.         sub.l    ts_start,d0
  4553.         ble.w    illegal_addr
  4554.  
  4555.         movem.l    ts_start,d0-d1
  4556.         btst    #0,d0            ;even address ?
  4557.         bne.w    illegal_addr
  4558.         btst    #0,d1            ;even address ?
  4559.         bne.w    illegal_addr
  4560.  
  4561.         clr.w    eval_size        ;.b par default
  4562.         bsr    evaluate        ;get nb of lives in d0
  4563.         bne.w    illegal_val
  4564.          move.w    eval_size,ts_size    ;.b .w .l (0,1,2)
  4565.  
  4566.         lea.l    tmp_mem,a0
  4567.         bsr    live_scan
  4568.  
  4569.         bra.w    end_command
  4570.  
  4571. ;--------------------------------------
  4572. ;-> d0=nb of lives
  4573. ;-> a0=start of trainer buffer in 'tmp_mem'
  4574.  
  4575. live_scan    move.l    ts_end,d1
  4576.         cmp.l    ts_start,d1
  4577.         beq.w    .noscan
  4578.  
  4579.         move.l    d0,d3
  4580.         tst.b    ts_deep
  4581.         beq.b    .nodeep
  4582.         addq.l    #1,d0            ;d0=max val
  4583.         subq.l    #1,d3            ;d3=min val
  4584. .nodeep
  4585.  
  4586.         move.w    ts_size,d1        ;.b .w .l (0,1,2)
  4587.         beq.w    .go_b
  4588.         cmp.w    #1,d1
  4589.         bne.b    .go_l
  4590.         lea.l    tmp_mem+tmp_mem_size,a3
  4591.         subq.l    #4,a3            ;for end signal
  4592.         move.l    ts_start,a1
  4593.         move.l    ts_end,a2
  4594. .seek1        move.l    a1,a4
  4595.         move.l    a1,watch
  4596.         CORR_ADDR 1
  4597.         cmp.w    (a4),d3
  4598.         bgt.b    .no_eg1
  4599.         cmp.w    (a4),d0
  4600.         blt.b    .no_eg1
  4601.         move.l    a1,(a0)+
  4602.         cmp.l    a3,a0
  4603.         bge.w    .end_seek
  4604. .no_eg1        addq.l    #2,a1
  4605.         tst.b    break
  4606.         bne.w    .end_seek
  4607.         cmp.l    a2,a1
  4608.         blt.b    .seek1
  4609.         bra.w    .end_seek
  4610.  
  4611. .go_l        lea.l    tmp_mem+tmp_mem_size,a3
  4612.         subq.l    #4,a3            ;for end signal
  4613.         move.l    ts_start,a1
  4614.         move.l    ts_end,a2
  4615. .seek2        move.l    a1,a4
  4616.         move.l    a1,watch
  4617.         CORR_ADDR 2
  4618.         cmp.l    (a4),d3
  4619.         bgt.b    .no_eg2
  4620.         cmp.l    (a4),d0
  4621.         blt.b    .no_eg2
  4622.         move.l    a1,(a0)+
  4623.         cmp.l    a3,a0
  4624.         bge.b    .end_seek
  4625. .no_eg2        addq.l    #2,a1
  4626.         tst.b    break
  4627.         bne.b    .end_seek
  4628.         cmp.l    a2,a1
  4629.         blt.b    .seek2
  4630.         bra.b    .end_seek
  4631.  
  4632. .go_b        lea.l    tmp_mem+tmp_mem_size,a3
  4633.         subq.l    #4,a3            ;for end signal
  4634.         move.l    ts_start,a1
  4635.         move.l    ts_end,a2
  4636. .seek3        move.l    a1,a4
  4637.         move.l    a1,watch
  4638.         CORR_ADDR 3
  4639.         cmp.b    (a4),d3
  4640.         bgt.b    .no_eg3
  4641.         cmp.b    (a4),d0
  4642.         blt.b    .no_eg3
  4643.         move.l    a1,(a0)+
  4644.         cmp.l    a3,a0
  4645.         bge.b    .end_seek
  4646. .no_eg3        addq.l    #1,a1
  4647.         tst.b    break
  4648.         bne.b    .end_seek
  4649.         cmp.l    a2,a1
  4650.         blt.b    .seek3
  4651.  
  4652. .end_seek    move.l    #-1,(a0)        ;end signal
  4653.  
  4654.         moveq    #8,d1
  4655.  
  4656.         lea.l    ts_txt,a0
  4657.         bsr    print
  4658.         move.l    ts_start,d0
  4659.         bsr    print_hex
  4660.         lea.l    ts1_txt,a0
  4661.         bsr    print
  4662.         move.l    a1,d0
  4663.         move.l    a1,ts_start
  4664.         bsr    print_hexCR
  4665.  
  4666. .noscan        rts
  4667.  
  4668. ts_txt        dc.b "Scan range : $",0
  4669. ts1_txt        dc.b " - $",0
  4670.         even
  4671.  
  4672. ;-------------- TF trainer find ---------------------------
  4673.  
  4674. cmd_tf
  4675.         bsr    evaluate        ;read new nb of lives
  4676.         bne.w    illegal_val
  4677.         move.l    d0,d7            ;new nb of lives=d7
  4678.  
  4679.         move.l    d7,d3
  4680.         move.l    d7,d4
  4681.         tst.b    ts_deep
  4682.         beq.b    .nodeep
  4683.         addq.l    #1,d3            ;d3=max val
  4684.         subq.l    #1,d4            ;d4=min val
  4685.  
  4686. .nodeep        lea.l    tmp_mem,a1
  4687.         move.l    a1,a2
  4688.         moveq    #-1,d2
  4689.  
  4690.         move.w    ts_size,d1
  4691.         bpl.b    .oksize
  4692.         lea.l    firstts_txt(pc),a0
  4693.         bsr    print
  4694.         bra.w    end_command
  4695. .oksize        beq.w    .go_b
  4696.  
  4697.         cmp.w    #1,d1
  4698.         bne.b    .go_l
  4699.  
  4700.         moveq    #8,d1
  4701. .seek1        tst.b    break
  4702.         bne.w    .end_seek
  4703.         cmp.l    (a1),d2
  4704.         beq.w    .end_seek
  4705.         move.l    (a1)+,a4
  4706.         CORR_ADDR 1
  4707.         cmp.w    (a4),d4
  4708.         bgt.b    .seek1
  4709.         cmp.w    (a4),d3
  4710.         blt.b    .seek1
  4711.         move.l    -4(a1),d0
  4712.         move.l    d0,(a2)+
  4713.         lea.l    tf_txt+1,a0
  4714.         bsr    conv_hex
  4715.         lea.l    tf_txt,a0
  4716.         bsr    print
  4717.         bra.b    .seek1
  4718.  
  4719. .go_l        moveq    #8,d1
  4720. .seek2        tst.b    break
  4721.         bne.w    .end_seek
  4722.         cmp.l    (a1),d2
  4723.         beq.w    .end_seek
  4724.         move.l    (a1)+,a4
  4725.         CORR_ADDR 2
  4726.         cmp.l    (a4),d4
  4727.         bgt.b    .seek2
  4728.         cmp.l    (a4),d3
  4729.         blt.l    .seek2
  4730.         move.l    -4(a1),d0
  4731.         move.l    d0,(a2)+
  4732.         lea.l    tf_txt+1,a0
  4733.         bsr    conv_hex
  4734.         lea.l    tf_txt,a0
  4735.         bsr    print
  4736.         bra.b    .seek2
  4737.  
  4738. .go_b        moveq    #8,d1
  4739. .seek3        tst.b    break
  4740.         bne.b    .end_seek
  4741.         cmp.l    (a1),d2
  4742.         beq.b    .end_seek
  4743.         move.l    (a1)+,a4
  4744.         CORR_ADDR 3
  4745.         cmp.b    (a4),d4
  4746.         bgt.b    .seek3
  4747.         cmp.b    (a4),d3
  4748.         blt.b    .seek3
  4749.         move.l    -4(a1),d0
  4750.         move.l    d0,(a2)+
  4751.         lea.l    tf_txt+1,a0
  4752.         bsr    conv_hex
  4753.         lea.l    tf_txt,a0
  4754.         bsr    print
  4755.         bra.b    .seek3
  4756.  
  4757. .end_seek    move.l    d2,(a2)        ;set new end signal
  4758.  
  4759.         cmp.l    #tmp_mem+tmp_mem_size-4,a2
  4760.         bge.b    .noscan
  4761.  
  4762.         move.l    a2,a0        ;tmp_mem buffer
  4763.         move.l    d7,d0        ;nb of lives
  4764.         bsr    live_scan
  4765.  
  4766. .noscan        tst.w    cursor_x
  4767.         beq.b    .no_CR
  4768.         lea.l    cr_txt,a0
  4769.         bsr    print
  4770. .no_CR        bra.w    end_command
  4771.  
  4772. firstts_txt    dc.b "First use TS command !",$a,0
  4773.         even
  4774.  
  4775. ;-------------- debug -------------------------------------
  4776.  
  4777. cmd_debug    bsr    remove_pic
  4778.  
  4779.         not.b    debug
  4780.         beq.w    .clear
  4781.         move.l    vbr_reg,a0
  4782.         move.l    $8(a0),exc8        ;BUS
  4783.         move.l    $c(a0),excC        ;Address
  4784.         move.l    $10(a0),exc10        ;Illegal
  4785.         move.l    $14(a0),exc14        ;Zero
  4786.         move.l    $28(a0),exc28        ;LineA
  4787.         move.l    $2C(a0),exc2C        ;LineF
  4788.  
  4789.         lea.l    debug_bus(pc),a1
  4790.         move.l    a1,$8(a0)
  4791.         lea.l    debug_addr(pc),a1
  4792.         move.l    a1,$C(a0)
  4793.         lea.l    debug_illegal(pc),a1
  4794.         move.l    a1,$10(a0)
  4795.         lea.l    debug_zero(pc),a1
  4796.         move.l    a1,$14(a0)
  4797.         lea.l    debug_linea(pc),a1
  4798.         move.l    a1,$28(a0)
  4799.         lea.l    debug_linef(pc),a1
  4800.         move.l    a1,$2c(a0)
  4801.  
  4802.         lea.l    debug1_txt,a0
  4803.         bsr    print
  4804.         bra.w    .okset
  4805.  
  4806. .clear        move.l    vbr_reg,a0
  4807.         lea.l    debug_bus(pc),a1
  4808.         cmp.l    $8(a0),a1
  4809.         bne.b    .no8
  4810.         move.l    exc8,$8(a0)
  4811. .no8        lea.l    debug_addr(pc),a1
  4812.         cmp.l    $C(a0),a1
  4813.         bne.b    .noC
  4814.         move.l    excC,$C(a0)
  4815. .noC        lea.l    debug_illegal(pc),a1
  4816.         cmp.l    $10(a0),a1
  4817.         bne.b    .no10
  4818.         move.l    exc10,$10(a0)
  4819. .no10        lea.l    debug_zero(pc),a1
  4820.         cmp.l    $14(a0),a1
  4821.         bne.b    .no14
  4822.         move.l    exc14,$14(a0)
  4823. .no14        lea.l    debug_linea(pc),a1
  4824.         cmp.l    $28(a0),a1
  4825.         bne.b    .no28
  4826.         move.l    exc28,$28(a0)
  4827. .no28        lea.l    debug_linef(pc),a1
  4828.         cmp.l    $2C(a0),a1
  4829.         bne.b    .no2C
  4830.         move.l    exc2C,$2C(a0)
  4831. .no2C
  4832.         lea.l    debug2_txt,a0
  4833.         bsr    print
  4834.  
  4835. .okset        bsr    set_pic
  4836.         bra.w    end_command
  4837.  
  4838. debug1_txt    dc.b "Debug mode on.",$a,0
  4839. debug2_txt    dc.b "Debug mode off.",$a,0
  4840.         even
  4841.  
  4842. debug_bus    move.b    #1,debug_entry
  4843.         jmp    monitor
  4844. debug_addr    move.b    #2,debug_entry
  4845.         jmp    monitor
  4846. debug_illegal    move.b    #3,debug_entry
  4847.         jmp    monitor
  4848. debug_zero    move.b    #4,debug_entry
  4849.         jmp    monitor
  4850. debug_linea    move.b    #5,debug_entry
  4851.         jmp    monitor
  4852. debug_linef    move.b    #6,debug_entry
  4853.         jmp    monitor
  4854.  
  4855. ;debug_entry 1=bus,2=addr,3=illegal,4=zero,5=linea,6=linef
  4856.  
  4857. ;-------------- print if entered from debug mode ----------
  4858.  
  4859. check_debug    movem.l    d0/a0,-(a7)
  4860.         moveq    #0,d0
  4861.         move.b    debug_entry,d0
  4862.         beq.b    .nodeb
  4863.         move.l    debug_txt(pc,d0.w*4),a0
  4864.         bsr    print
  4865.         sf    debug_entry
  4866. .nodeb        movem.l    (a7)+,d0/a0
  4867.         rts
  4868.  
  4869. debug_txt    dc.l 0
  4870.         dc.l .bus_txt
  4871.         dc.l .addr_txt
  4872.         dc.l .illegal_txt
  4873.         dc.l .zero_txt
  4874.         dc.l .linea_txt
  4875.         dc.l .linef_txt
  4876.  
  4877. .bus_txt    dc.b "Debug mode: Bus error",$a,0
  4878. .addr_txt    dc.b "Debug mode: Illegal address",$a,0
  4879. .illegal_txt    dc.b "Debug mode: Illegal instruction",$a,0
  4880. .zero_txt    dc.b "Debug mode: Division by zero",$a,0
  4881. .linea_txt    dc.b "Debug mode: Line-A instruction",$a,0
  4882. .linef_txt    dc.b "Debug mode: Line-F instruction",$a,0
  4883.         even
  4884.  
  4885. ;----------------------------------------------------------
  4886. ;-------------- jmp here when you finish a command --------
  4887. ;-------------- which had something to do with the disk ---
  4888.  
  4889. ;NODISK_ERR        equ 1
  4890. ;TRACKCORRUPT_ERR    equ 2
  4891. ;BADCHECKSUM_ERR    equ 3
  4892. ;NOTDOS_ERR        equ 4
  4893. ;WRITEPROTECT_ERR    equ 5
  4894. ;CREATEFILE_ERR        equ 6
  4895. ;FILENOTFOUND_ERR    equ 7
  4896. ;DISKFULL_ERR        equ 8
  4897. ;FILEEXIST_ERR        equ 9
  4898. ;DEVICENOTFOUND_ERR    equ 10
  4899. ;ILLEGALPATH_ERR    equ 11
  4900. ;NOFFS_ERR        equ 12
  4901. ;IDE_ERR        equ 13
  4902. ;NOTEMPTY_ERR        equ 14
  4903.  
  4904. end_disk:    bsr    flush_fbuffer        ;flush file buffers
  4905.         bsr    motor_off
  4906.         clr.l    bitmap_part        ;clear bitmap buffer
  4907.  
  4908.         clr.l    file_handle1        ;free
  4909.         clr.l    file_handle2        ;both file_handle
  4910.  
  4911.         lea.l    track_sector,a0
  4912.         moveq    #-1,d1
  4913.         move.l    d1,(a0)+
  4914.         move.l    d1,(a0)+
  4915.         move.l    d1,(a0)+
  4916.         move.w    d1,track_buffer_no
  4917.  
  4918.         move.w    drive_err,d0
  4919.         beq.w    .noerr
  4920.         clr.w    drive_err
  4921.  
  4922.         lea.l    no_disk_txt,a0        ;1
  4923.         subq.w    #1,d0
  4924.         beq.w    .ok
  4925.         lea.l    corrupt_txt,a0        ;2
  4926.         subq.w    #1,d0
  4927.         beq.w    .ok
  4928.         lea.l    bad_sum_txt,a0        ;3
  4929.         subq.w    #1,d0
  4930.         beq.b    .ok
  4931.         lea.l    NotDOS_txt,a0        ;4
  4932.         subq.w    #1,d0
  4933.         beq.b    .ok
  4934.         lea.l    WriteProt_txt,a0    ;5
  4935.         subq.w    #1,d0
  4936.         beq.b    .ok
  4937.         lea.l    CreateFile_txt,a0    ;6
  4938.         subq.w    #1,d0
  4939.         beq.b    .ok
  4940.         lea.l    FileNotFound_txt,a0    ;7
  4941.         subq.w    #1,d0
  4942.         beq.b    .ok
  4943.         lea.l    DiskFull_txt,a0        ;8
  4944.         subq.w    #1,d0
  4945.         beq.b    .ok
  4946.         lea.l    FileExists_txt,a0    ;9
  4947.         subq.w    #1,d0
  4948.         beq.b    .ok
  4949.         lea.l    DeviceNotFound_txt,a0    ;10
  4950.         subq.w    #1,d0
  4951.         beq.b    .ok
  4952.         lea.l    IllegalPath_txt,a0    ;11
  4953.         subq.w    #1,d0
  4954.         beq.b    .ok
  4955.         lea.l    NoFFS_txt,a0        ;12
  4956.         subq.w    #1,d0
  4957.         beq.b    .ok
  4958.         lea.l    IDEerr_txt,a0        ;13
  4959.         subq.w    #1,d0
  4960.         beq.b    .ok
  4961.         lea.l    NotEmpty_txt,a0        ;14
  4962.  
  4963.  
  4964. ;        subq.w    #1,d0
  4965. ;        beq.b    .ok
  4966. ;        nop
  4967. .ok
  4968.         bsr    print
  4969.  
  4970. .noerr        tst.b    small_pic
  4971.         beq.b    .nosmall
  4972.         sf    no_print
  4973.         bsr    print_page
  4974.         sf    small_pic
  4975. .nosmall
  4976.  
  4977.         bra.w    end_command
  4978.  
  4979.  
  4980. ;-------------- type mem ------------------------
  4981.  
  4982. cmd_type    bsr evaluate
  4983.         bne.w    illegal_addr
  4984.         move.l    d0,a0
  4985.         bsr    print
  4986.         bra.w    end_command
  4987.  
  4988. ;-------------- find ----------------------------
  4989.  
  4990. cmd_f        bsr    evaluate
  4991.         bne.w    illegal_addr
  4992.         move.l    d0,find_start
  4993.         bsr    evaluate
  4994.         bne.w    illegal_addr
  4995.         move.l    d0,find_end
  4996.         movem.l    find_start,d0-d1
  4997.         cmp.l    d0,d1
  4998.         ble.w    illegal_addr
  4999.  
  5000.         lea.l    find_list,a1
  5001.         moveq    #0,d1            ;nb bytes
  5002. .loop        clr.w    eval_size
  5003.         bsr    evaluate
  5004.         bmi.w    illegal_val
  5005.         bgt.b    .end_find
  5006.         move.w    eval_size,d2
  5007.         move.w    d2,d3
  5008. .next        addq.w    #1,d1
  5009.         move.b    d0,(a1,d2.w)
  5010.         lsr.l    #8,d0
  5011.         dbf    d2,.next
  5012.         addq.w    #1,d3
  5013.         add.w    d3,a1
  5014.         cmp.l    #find_list+80,a1
  5015.         blt.b    .loop
  5016.  
  5017. .end_find    subq.w    #1,d1
  5018.         bmi.w    illegal_val
  5019.         movem.l    find_start,a0-a1
  5020.         cmp.l    a0,a1
  5021.         ble.w    illegal_addr
  5022.  
  5023.  
  5024.         lea.l    find_list,a2
  5025.         move.b    (a2)+,d0
  5026. .seek        cmp.l    a1,a0
  5027.         bge.b    .end_seek
  5028.         tst.b    break
  5029.         bne.b    .end_seek
  5030.         move.l    a0,watch
  5031.         move.l    a0,a4
  5032.         CORR_ADDR
  5033.         addq.l    #1,a0
  5034.         cmp.b    (a4)+,d0
  5035.         bne.b    .seek
  5036.         move.w    d1,d2
  5037.         move.l    a2,a3
  5038.         bra.b    .dbf
  5039. .comp        move.b    (a3)+,d3
  5040.         cmp.b    (a4)+,d3
  5041.         bne.b    .seek
  5042. .dbf        dbf    d2,.comp
  5043.         movem.l    d0-d1/a0,-(a7)
  5044.         move.l    a0,d0
  5045.         subq.l    #1,d0
  5046.         lea.l    ev_line,a0
  5047.         move.w    #$2020,8(a0)
  5048.         clr.b    10(a0)
  5049.         moveq    #8,d1
  5050.         bsr    conv_hex
  5051.         bsr    print
  5052.         movem.l    (a7)+,d0-d1/a0
  5053.         bra.b    .seek
  5054.  
  5055. .end_seek    tst.w    cursor_x
  5056.         beq.b    .no_CR
  5057.         lea.l    cr_txt,a0
  5058.         bsr    print
  5059. .no_CR
  5060.         bra.w    end_command
  5061.  
  5062. cr_txt        dc.b $a,0
  5063.  
  5064. ;-------------- find instruction ----------------
  5065.  
  5066. cmd_fi        bsr    evaluate
  5067.         bne.w    illegal_addr
  5068.         and.w    #$fffe,d0
  5069.         move.l    d0,find_start
  5070.         bsr    evaluate
  5071.         bne.w    illegal_addr
  5072.         and.w    #$fffe,d0
  5073.         move.l    d0,find_end
  5074.  
  5075.         movem.l    find_start,d0-d1
  5076.         cmp.l    d0,d1
  5077.         ble.w    illegal_addr
  5078.  
  5079.         lea.l    find_list,a1
  5080.         bsr    read_name
  5081.         tst.b    (a1)
  5082.         beq.w    illegal_string
  5083.  
  5084. .re_jok        lea.l    find_list,a0
  5085.         cmp.b    #'*',(a0)    ;remove jokers at begining of line
  5086.         bne.b    .lower
  5087. .shift        move.b    1(a0),(a0)+
  5088.         bne.b    .shift
  5089.         bra.b    .re_jok
  5090.  
  5091. .lower        move.b    (a0),d0
  5092.         beq.b    .end_list
  5093.         bsr    lower_case
  5094.         move.b    d0,(a0)+
  5095.         bra.b    .lower
  5096.  
  5097. .end_list    movem.l    find_start,a0-a1
  5098.         cmp.l    a0,a1
  5099.         ble.w    illegal_addr
  5100.  
  5101.         move.l    a1,d7
  5102.         lea.l    ev_line,a1
  5103.         move.l    a1,d6
  5104.         lea.l    find_list,a1
  5105.         move.l    a1,d5
  5106.         moveq    #$a,d4
  5107.  
  5108. .loop2        cmp.l    d7,a0
  5109.         bge.w    .end_fi
  5110.         tst.b    break
  5111.         bne.w    .end_fi
  5112.  
  5113.         move.l    a0,watch
  5114.         move.l    a0,-(a7)
  5115.         move.l    a0,a4
  5116.         bsr    corr_addr
  5117.         move.l    d6,a0            ;ev_line
  5118.         moveq    #%100,d0    ;lower case, no d $address,indirect
  5119.         bsr    disassemble
  5120.  
  5121.         move.l    d5,a0            ;find_list
  5122.         move.b    (a0)+,d0
  5123.         move.l    d6,a1            ;ev_line
  5124. .seek        move.b    (a1)+,d1
  5125.         cmp.b    d4,d1
  5126.         beq.b    .no_fi
  5127.         cmp.b    d0,d1
  5128.         bne.b    .seek
  5129.         move.l    a0,a2
  5130.         move.l    a1,a3
  5131. .loop        move.b    (a2)+,d2
  5132.         beq.b    .ok
  5133.         move.b    (a3)+,d1
  5134.         cmp.b    d4,d1
  5135.         beq.b    .seek
  5136.         cmp.b    #'*',d2            ;joker
  5137.         beq.b    .loop
  5138.         cmp.b    d2,d1
  5139.         beq.b    .loop
  5140.         bra.b    .seek
  5141.  
  5142. .ok
  5143.         move.l    (a7),a4
  5144.         CORR_ADDR
  5145.         move.l    d6,a0            ;ev_line
  5146.         moveq    #%111,d0    ;upper case, d $address, indirect
  5147.         bsr    disassemble
  5148.  
  5149.         move.l    d6,a0
  5150.         bsr    print            ;print disas. line
  5151.  
  5152. .no_fi        move.l    (a7)+,a0
  5153.         addq.l    #2,a0
  5154.         bra.w    .loop2
  5155.  
  5156. .end_fi
  5157.         bra.w    end_command
  5158.  
  5159. ;-------------- find instruction famicom -------------
  5160.  
  5161. cmd_fif        bsr    evaluate
  5162.         bne.w    illegal_addr
  5163.         move.l    d0,find_start
  5164.         bsr    evaluate
  5165.         bne.w    illegal_addr
  5166.         move.l    d0,find_end
  5167.  
  5168.         movem.l    find_start,d0-d1
  5169.  
  5170.         lea.l    find_list,a1
  5171.         bsr    read_name
  5172.         tst.b    (a1)
  5173.         beq.w    illegal_string
  5174.  
  5175.         lea.l    find_list,a0
  5176. .upper        move.b    (a0),d0
  5177.         beq.b    .end_list
  5178.         bsr    upper_case
  5179.         move.b    d0,(a0)+
  5180.         bra.b    .upper
  5181.  
  5182. .end_list    movem.l    find_start,a0-a1
  5183.         cmp.l    a0,a1
  5184.         ble.w    illegal_addr
  5185.  
  5186.         move.l    a1,d7
  5187.         lea.l    ev_line+10,a1
  5188.         move.l    a1,d6
  5189.         lea.l    find_list,a1
  5190.         move.l    a1,d5
  5191.         moveq    #$a,d4
  5192.  
  5193. .loop2        cmp.l    d7,a0
  5194.         bge.w    .end_fi
  5195.         tst.b    break
  5196.         bne.w    .end_fi
  5197.  
  5198.         move.l    a0,watch
  5199.         move.l    a0,-(a7)
  5200.         move.l    a0,a4
  5201.         CORR_ADDR
  5202.         move.l    d6,a0            ;ev_line+10
  5203.         bsr    f_disassemble
  5204.  
  5205.         move.l    d5,a0            ;find_list
  5206.         move.b    (a0)+,d0
  5207.         move.l    d6,a1            ;ev_line+10
  5208. .seek        move.b    (a1)+,d1
  5209.         cmp.b    d4,d1
  5210.         beq.b    .no_fi
  5211.         cmp.b    d0,d1
  5212.         bne.b    .seek
  5213.         move.l    a0,a2
  5214.         move.l    a1,a3
  5215. .loop        move.b    (a2)+,d2
  5216.         beq.b    .ok
  5217.         move.b    (a3)+,d1
  5218.         cmp.b    d4,d1
  5219.         beq.b    .seek
  5220.         cmp.b    d2,d1
  5221.         beq.b    .loop
  5222.         bra.b    .seek
  5223.  
  5224. .ok        move.l    (a7),d0
  5225.         moveq    #8,d1
  5226.         lea.l    ev_line,a0
  5227.         move.b    #' ',9(a0)
  5228.         move.b    #' ',(a0)+
  5229.         bsr    conv_hex
  5230.         lea.l    ev_line,a0
  5231.         bsr    print
  5232. .no_fi        move.l    (a7)+,a0
  5233.         addq.l    #1,a0
  5234.         bra.w    .loop2
  5235.  
  5236. .end_fi
  5237.         bra.w    end_command
  5238.  
  5239. ;-------------- change drive no -----------------
  5240. cmd_drive    bsr    evaluate
  5241.         bmi.w    illegal_val
  5242.         beq.b    .chg
  5243.         moveq    #0,d0
  5244.         move.w    drive,d0
  5245.         subq.w    #3,d0
  5246. .chg        moveq    #1,d1
  5247.         cmp.l    d1,d0
  5248.         bgt.w    illegal_val
  5249.         tst.l    d0
  5250.         bmi.w    illegal_val
  5251.         lea.l    drive_present,a0
  5252.         tst.b    (a0,d0.w)        ;drive is present ?
  5253.         beq.w    illegal_val
  5254.         addq.w    #3,d0
  5255.         move.w    d0,drive
  5256.         subq.b    #3,d0
  5257.         lea.l    drive_txt,a0
  5258.         bsr    print
  5259.         moveq    #1,d1
  5260.         bsr    print_hexCR
  5261.         bra.w    end_command
  5262.  
  5263. ;-------------- exit monitor --------------------
  5264.  
  5265. cmd_x        st    escape
  5266.         bra.w    end_command
  5267.  
  5268.  
  5269. ;-------------- KILL --------------------------------------
  5270.  
  5271. cmd_kill    st    escape
  5272.         st    kill
  5273.  
  5274.         bra.w    end_command
  5275.  
  5276. ;-------------- REBOOT ------------------------------------
  5277.  
  5278. cmd_reboot
  5279.         bsr    remove_pic
  5280.  
  5281.         move.l    $4.w,a0
  5282.         move.l    a0,d0
  5283.         lsr.l    #1,d0
  5284.         bcs.w    .nosafe
  5285.         lea.l    34(a0),a1
  5286.         moveq    #0,d0
  5287.         moveq    #$18-1,d1
  5288. .add        add.w    (a1)+,d0
  5289.         dbf    d1,.add
  5290.         not.w    d0
  5291.         cmp.w    82(a0),d0
  5292.         bne.w    .nosafe
  5293.  
  5294.         bsr    set_pic
  5295.  
  5296.         lea.l    surereboot_txt(pc),a0
  5297.         bsr    print
  5298.         bsr    get_key
  5299.         lea.l    sure2_txt(pc),a0
  5300.         bsr    print
  5301.         cmp.b    #'y',d0
  5302.         bne.b    .no
  5303.  
  5304.         bsr    remove_pic
  5305.  
  5306.         move.l    $4.w,a0
  5307.         clr.l    ColdCapture(a0)
  5308.         move.l    #cool-start+$50000,CoolCapture(a0)
  5309.  
  5310.         st    reboot
  5311.  
  5312.         lea.l    34(a0),a1
  5313.         moveq    #0,d0
  5314.         moveq    #$18-1,d1
  5315. .add2        add.w    (a1)+,d0
  5316.         dbf    d1,.add2
  5317.         not.w    d0
  5318.         move.w    d0,82(a0)
  5319.  
  5320.         move.l    $f80004,a0
  5321.         subq.l    #2,a0
  5322.         move.l    a0,pc_reg
  5323.         move.w    #$2700,sr_reg
  5324.         st    escape
  5325.  
  5326.         bsr    set_pic
  5327.  
  5328. .no        bra.w    end_command
  5329.  
  5330. .nosafe        lea.l    nosafe_txt(pc),a0
  5331.         bsr    print
  5332.         bra.w    end_command
  5333.  
  5334. nosafe_txt    dc.b "HRTmon can't reboot and stay resident !",$a
  5335.         dc.b "You have to perform this operation when ExecBase is still valid !",$a,0
  5336.  
  5337. surereboot_txt    dc.b "The machine will reboot!",$a
  5338.         dc.b "HRTmon will still be accessible to debug bootdisks",$a
  5339.         dc.b "Are you sure you want to continue ? (y/n)",$d,0
  5340.         even
  5341.  
  5342.  
  5343. cool        movem.l    d1-a6,-(a7)
  5344.  
  5345.         move.l    $4.w,a0
  5346.         clr.l    CoolCapture(a0)
  5347.         lea.l    34(a0),a1
  5348.         moveq    #0,d0
  5349.         moveq    #$18-1,d1
  5350. .add        add.w    (a1)+,d0
  5351.         dbf    d1,.add
  5352.         not.w    d0
  5353.         move.w    d0,82(a0)
  5354.  
  5355.         lea.l    $50000,a0
  5356.         lea.l    start,a1
  5357.         move.l    a1,a2
  5358.         move.w    #$2f000/4-1,d0
  5359. .copy        move.l    (a0)+,(a1)+        ;restore HRTmon to its place
  5360.         dbf    d0,.copy
  5361.  
  5362.         move.l    $4.w,a6
  5363.         jsr    -636(a6)        ;clear cache
  5364.  
  5365.         jmp    .next
  5366.  
  5367. .next        move.l    $4.w,a6
  5368.         lea.l    .super(pc),a5
  5369.         jsr    -30(a6)
  5370.  
  5371.         move.l    mon_size(pc),d0
  5372.         beq.b    .noalloc
  5373.         lea.l    start,a1
  5374.         jsr    -204(a6)
  5375.         tst.l    d0
  5376.         bne.b    .noalloc
  5377.         clr.l    mon_size        ;alloc failed
  5378. .noalloc
  5379.         sf    entered
  5380.  
  5381.  
  5382. ;.wait        move.w    $dff006,d0
  5383. ;        and.w    #$ff,d0
  5384. ;        move.w    #0,$dff106
  5385. ;        move.w    d0,$dff180
  5386. ;        btst    #6,$bfe001
  5387. ;        bne.b    .wait
  5388.  
  5389.         movem.l    (a7)+,d1-a6
  5390.         moveq    #0,d0
  5391.         rts
  5392.  
  5393. .super        movec    VBR,a4
  5394.         move.l    a4,old_vbr
  5395.         lea.l    new_except,a0
  5396.  
  5397.         move.l    a0,a1
  5398.         lea.l    except_entry(pc),a2
  5399.         move.w    #$400/4-1,d1
  5400. .init        move.l    a2,(a1)+
  5401.         dbf    d1,.init
  5402.  
  5403.         suba.l    a1,a1
  5404.         move.w    #$400/4-1,d1
  5405. .copy2        move.l    (a4)+,(a1)+
  5406.         dbf    d1,.copy2
  5407.  
  5408.         move.l    $7c(a0),oldlev7
  5409.         move.l    #monitor,$7c(a0)
  5410.         movec    a0,VBR
  5411.  
  5412.         rte
  5413.  
  5414. ;-------------- restart program at address ------
  5415.  
  5416. cmd_g        bsr    evaluate
  5417.         bmi.w    illegal_addr
  5418.         bne.b    .noaddr
  5419.         move.l    d0,pc_reg
  5420. .noaddr        st    escape
  5421.         bra.w    end_command
  5422.  
  5423. ;-------------- Load AmigaDOS file --------------
  5424.  
  5425. cmd_l        lea.l    ev_line,a1
  5426.         bsr    read_name
  5427.         tst.b    (a1)
  5428.         beq.w    illegal_name
  5429.  
  5430.         bsr    evaluate
  5431.         bne.w    illegal_addr
  5432.         tst.l    d0
  5433.         bmi.w    illegal_addr
  5434.         move.l    d0,d4
  5435.  
  5436.         bsr    remove_pic
  5437.  
  5438.         move.l    #ev_line,d1
  5439.         moveq    #0,d2            ;old file
  5440.         bsr    open_file
  5441.         move.l    d0,d7
  5442.         beq.b    .noopen
  5443.         move.l    d4,d2
  5444.         move.l    d7,a1
  5445.         move.l    file_size(a1),d3
  5446.         move.l    d3,d6
  5447.         move.l    d3,d1
  5448.         add.l    d2,d1            ;end address
  5449.         move.l    d2,d0
  5450.         move.l    d7,d1
  5451.         bsr    read_file
  5452. .bad        move.l    d7,d1
  5453.         bsr    close_file
  5454.  
  5455. .noopen        bsr    set_pic
  5456.  
  5457.         tst.w    drive_err
  5458.         bne.b    .end
  5459.  
  5460.         lea.l    file_len_txt,a0
  5461.         bsr    print
  5462.         moveq    #8,d1
  5463.         move.l    d6,d0
  5464.         bsr    print_hexCR
  5465.  
  5466. .end        bra.w    end_disk
  5467.  
  5468. ;-------------- cd dir --------------------------
  5469.  
  5470. cmd_cd        lea.l    ev_line,a1
  5471.         bsr    read_name
  5472.         tst.b    (a1)
  5473.         beq.b    .nochg
  5474.  
  5475.         move.l    #ev_line,d1
  5476.         bsr    change_dir
  5477.  
  5478. .nochg        lea.l    ev_line,a0
  5479.         sf    (a0)
  5480.         move.l    a0,d1
  5481.         bsr    ExNext
  5482.         tst.l    d0
  5483.         bmi.b    .err
  5484.  
  5485.         move.l    d1,a3            ;partition
  5486.         move.l    d2,d0            ;parent block no
  5487.         bsr    print_path        ;path
  5488.  
  5489. .err        bra.w    end_disk
  5490.  
  5491. ;-------------- dir -----------------------------
  5492.  
  5493. cmd_dir        lea.l    ev_line,a1
  5494.         bsr    read_name
  5495.  
  5496.         moveq    #0,d6            ;nb files printed
  5497.  
  5498.         move.l    #ev_line,d1
  5499.         bsr    ExNext
  5500.         tst.l    d0
  5501.         bmi.w    .err
  5502.  
  5503.         move.l    d0,-(a7)
  5504.         move.l    d1,a3            ;partition
  5505.         move.l    d2,d0            ;parent block no
  5506.         bsr    print_path        ;path
  5507.         move.l    (a7)+,d0
  5508.  
  5509.         tst.l    d0            ;empty dir ?
  5510.         beq.w    .err
  5511.  
  5512. .loop        addq.l    #1,d6
  5513.         move.l    d0,a1
  5514.         lea.l    general_txt,a0
  5515.         move.b    #' ',d0
  5516.         move.l    a0,a2
  5517.         moveq    #31-1,d2
  5518. .fill        move.b    d0,(a2)+
  5519.         dbf    d2,.fill
  5520.         sf    (a2)
  5521.  
  5522.         lea.l    file_name(a1),a2
  5523.         moveq    #0,d0
  5524.         move.b    (a2)+,d0        ;get file name size
  5525.         bra.b    .godbf
  5526. .copyn        move.b    (a2)+,(a0)+
  5527. .godbf        dbf    d0,.copyn
  5528.         lea.l    general_txt,a0
  5529.         bsr    print            ;print filename
  5530.  
  5531.         tst.b    file_dir(a1)
  5532.         beq.b    .okfile
  5533.         lea.l    dir_txt,a0
  5534.         bsr    print
  5535.         bra.b    .okdir
  5536. .okfile        move.l    file_size(a1),d0
  5537.         moveq    #7,d1
  5538.         bsr    print_dec
  5539.  
  5540. .okdir        lea.l    spc_txt,a0
  5541.         bsr    print
  5542.  
  5543.         move.l    d6,d0        ;nb files printed in d0
  5544.         move.w    screen_height,d1
  5545.         subq.w    #5,d1
  5546.         lsl.w    #1,d1
  5547.         divu    d1,d0        ;pause after 46(PAL) files printed
  5548.         swap    d0
  5549.         tst.w    d0
  5550.         bne.b    .no46
  5551.         bsr    get_key        ;wait for key pressed
  5552. .no46
  5553.         tst.b    break
  5554.         bne.b    .err
  5555.  
  5556.         move.l    a1,d1
  5557.         bsr    ExNext
  5558.         tst.l    d0
  5559.         bgt.w    .loop
  5560.  
  5561. .err        lsr.l    #1,d6
  5562.         bcc.b    .nocr
  5563.         lea.l    cr_txt,a0
  5564.         bsr    print
  5565.  
  5566. .nocr
  5567.         bra.w    end_disk
  5568.  
  5569. dir_txt        dc.b "   (DIR)",0
  5570. spc_txt        dc.b " ",0
  5571.         even
  5572.  
  5573. ;-------------- calculate BootBlock checksum --------------
  5574.  
  5575. cmd_bb        bsr    evaluate
  5576.         bne.w    illegal_addr
  5577.         move.l    d0,a0
  5578.         move.l    a0,a1
  5579.         clr.l    4(a1)
  5580.  
  5581.         moveq    #0,d0
  5582.         move.w    #512*2/4-1,d1
  5583. .add        add.l    (a0)+,d0
  5584.         bcc.b    .noc
  5585.         addq.l    #1,d0
  5586. .noc        dbf    d1,.add
  5587.         not.l    d0
  5588.  
  5589.         move.l    d0,4(a1)
  5590.  
  5591.         bra.w    end_command
  5592.  
  5593. ;-------------- floppy access -------------------
  5594.  
  5595. cmd_disk1    move.b    #'R',d0
  5596.         bra.b    go_disk
  5597. cmd_disk2    move.b    #'W',d0
  5598. go_disk        move.b    d0,rwsec
  5599.  
  5600.         bsr    evaluate
  5601.         bne.w    illegal_addr
  5602.         move.l    d0,sec_addr
  5603.         bsr    evaluate
  5604.         bne.w    illegal_val
  5605.         tst.l    d0
  5606.         bmi.w    illegal_val
  5607.         cmp.l    #1759,d0
  5608.         bgt.w    illegal_val
  5609.         move.w    d0,strtsec
  5610.         move.l    d0,d1
  5611.  
  5612.         bsr    evaluate
  5613.         bne.w    illegal_val
  5614.         tst.l    d0
  5615.         bmi.w    illegal_val
  5616.         move.w    d0,nbsec
  5617.         add.l    d0,d1
  5618.         cmp.l    #1760,d1
  5619.         bgt.w    illegal_val
  5620.  
  5621.         move.l    sec_addr,d0
  5622.         move.w    nbsec,d1
  5623.         mulu    #512,d1
  5624.         add.l    d0,d1
  5625.  
  5626.         bsr    remove_pic
  5627.  
  5628.         bsr    test_present
  5629.         bne.b    .end_write
  5630.  
  5631.         move.l    sec_addr,a0
  5632.         movem.w    strtsec,d0-d1
  5633.         cmp.b    #'W',rwsec
  5634.         bne.b    .no_write
  5635.  
  5636.         bsr    write2
  5637.  
  5638.         bsr    force_change
  5639.  
  5640.         bra.b    .end_write
  5641.  
  5642. .no_write    bsr    read2
  5643. .end_write    bsr    set_pic
  5644.         bra.w    end_disk
  5645.  
  5646. ;----------------------------------------------------------
  5647. ;-------------- test if a disk is present -----------------
  5648. ;-------------- if disk changed then flush track_buffer ---
  5649. ;-------------- used by non FileSystem commands (RS,WS...)-
  5650.  
  5651. ;<- FLAGS 0=ok_present
  5652.  
  5653. test_present    movem.l    d0/a3,-(a7)
  5654.         lea.l    floppy0,a3
  5655.         cmp.w    #3,drive
  5656.         beq.b    .go0
  5657.         lea.l    floppy1,a3
  5658. .go0        moveq    #0,d0            ;test cmd
  5659.         bsr    floppy_change
  5660.         tst.w    drive_err
  5661.         movem.l    (a7)+,d0/a3
  5662.         rts
  5663.  
  5664. ;--------------------------------------------------------------------
  5665. ;-------------- force change_disk to floppy selected in 'drive' -----
  5666.  
  5667. ;-> drive
  5668.  
  5669. force_change    movem.l    d0/a2-a3,-(a7)
  5670.         lea.l    floppy0,a3
  5671.         cmp.w    #3,drive
  5672.         beq.b    .f0
  5673.         cmp.w    #4,drive
  5674.         bne.b    .end
  5675.         lea.l    floppy1,a3
  5676. .f0        move.l    part_device(a3),a2
  5677.         clr.l    part_filesystem(a3)
  5678.         moveq    #1,d0            ;force change cmd
  5679.         jsr    CHANGE_CMD(a2)
  5680.         clr.l    bitmap_part        ;clear bitmap buffer
  5681. .end        movem.l    (a7)+,d0/a2-a3
  5682.         rts
  5683.  
  5684. ;-------------- disk check ----------------------
  5685.  
  5686. cmd_diskchk
  5687.  
  5688.         moveq    #0,d6
  5689.         move.w    #160-1,d7
  5690. .check        move.l    d6,d0
  5691.         lea.l    fbuf1,a0
  5692.         bsr    read_fsector
  5693.         tst.w    drive_err
  5694.         bne.b    .error
  5695.         tst.b    break
  5696.         bne.b    .error
  5697.         add.w    #11,d6
  5698.         dbf    d7,.check
  5699.  
  5700.         lea.l    .ok_txt(pc),a0
  5701.         bsr    print
  5702.  
  5703. .error
  5704.         bsr    force_change
  5705.  
  5706.         bra.w    end_disk
  5707.  
  5708. .ok_txt        dc.b "Floppy disk is OK.",$a,0
  5709.  
  5710. ;-------------- format disk ---------------------
  5711.  
  5712. fconfirm1_txt    dc.b "Format disk in drive ",0
  5713. fconfirm2_txt    dc.b " (y/n) ?",$d,0
  5714.         even
  5715.  
  5716. cmd_format    lea.l    ev_line,a1
  5717.         bsr.w    read_name
  5718.  
  5719.         lea.l    fconfirm1_txt,a0
  5720.         bsr    print
  5721.         move.w    drive,d0
  5722.         subq.w    #3,d0
  5723.         moveq    #1,d1
  5724.         bsr    print_dec
  5725.         lea.l    fconfirm2_txt,a0
  5726.         bsr    print
  5727.  
  5728.         bsr    get_key
  5729.         lea.l    diskclr_txt(pc),a0
  5730.         bsr    print
  5731.         cmp.b    #'y',d0
  5732.         bne.w    .endformat
  5733.  
  5734.         bsr    test_present
  5735.         bne.w    .endformat
  5736.  
  5737.         lea.l    $40000,a0        ;dummy addr for format
  5738.         moveq    #0,d0
  5739.         moveq    #-1,d1            ;format all disk
  5740.         moveq    #-1,d7            ;write
  5741.         bsr    access
  5742.  
  5743.         tst.b    break
  5744.         bne.b    .break
  5745.  
  5746.         lea.l    format_block,a0
  5747.         lea.l    secbuf,a1
  5748.         moveq    #512/16-1,d0
  5749. .copy        move.l    (a0)+,(a1)+
  5750.         move.l    (a0)+,(a1)+
  5751.         move.l    (a0)+,(a1)+
  5752.         move.l    (a0)+,(a1)+
  5753.         dbf    d0,.copy
  5754.  
  5755.         lea.l    ev_line,a1
  5756.         tst.b    (a1)
  5757.         beq.w    .no_set
  5758.         move.l    a1,d1            ;source name (ended by a zero)
  5759.         lea.l    secbuf+108*4,a2        ;dest BCPL
  5760.         bsr    copy_name2
  5761. .no_set
  5762.         lea.l    secbuf,a0
  5763.         bsr    calc_sum
  5764.         move.w    #880,d0
  5765.         bsr    write_fsector
  5766.         lea.l    format_block+512,a0
  5767.         move.w    #881,d0
  5768.         bsr    write_fsector
  5769.         bsr    write_flush
  5770.  
  5771. .break        bsr    force_change
  5772.  
  5773. .endformat
  5774.  
  5775.         bra.w    end_disk
  5776.  
  5777. ;-------------- FORMATQ ------------------------
  5778. cmd_formatq    lea.l    ev_line,a1
  5779.         bsr.w    read_name
  5780.  
  5781.         lea.l    fconfirm1_txt,a0
  5782.         bsr    print
  5783.         move.w    drive,d0
  5784.         subq.w    #3,d0
  5785.         moveq    #1,d1
  5786.         bsr    print_dec
  5787.         lea.l    fconfirm2_txt,a0
  5788.         bsr    print
  5789.  
  5790.         bsr    get_key
  5791.         lea.l    diskclr_txt(pc),a0
  5792.         bsr    print
  5793.         cmp.b    #'y',d0
  5794.         bne.w    .endformat
  5795.  
  5796.         bsr    test_present
  5797.         bne.w    .endformat
  5798.  
  5799.         lea.l    format_block,a0
  5800.         lea.l    secbuf,a1
  5801.         moveq    #512/16-1,d0
  5802. .copy        move.l    (a0)+,(a1)+
  5803.         move.l    (a0)+,(a1)+
  5804.         move.l    (a0)+,(a1)+
  5805.         move.l    (a0)+,(a1)+
  5806.         dbf    d0,.copy
  5807.  
  5808.         lea.l    ev_line,a1
  5809.         tst.b    (a1)
  5810.         beq.b    .no_set
  5811.         move.l    a1,d1            ;source name (ended by a zero)
  5812.         lea.l    secbuf+108*4,a2        ;dest BCPL
  5813.         bsr    copy_name2
  5814. .no_set
  5815.         lea.l    secbuf,a0
  5816.         bsr    calc_sum
  5817.         move.w    #880,d0
  5818.         bsr    write_fsector
  5819.         lea.l    format_block+512,a0
  5820.         move.w    #881,d0
  5821.         bsr    write_fsector
  5822.  
  5823.         lea.l    secbuf,a0
  5824.         move.l    a0,a1
  5825.         moveq    #512/4-1,d0
  5826. .clr        clr.l    (a1)+
  5827.         dbf    d0,.clr
  5828.         move.l    #$444f5301,(a0)        ;'DOS',1 (FFS)
  5829.         moveq    #0,d0
  5830.         bsr    write_fsector
  5831.  
  5832.         bsr    write_flush
  5833.  
  5834.         bsr    force_change
  5835.  
  5836. .endformat
  5837.         bra.w    end_disk
  5838.  
  5839. ;-------------- evaluate expression -------------
  5840. cmd_ev        bsr    evaluate
  5841.         bne.w    illegal_expr
  5842.  
  5843.         lea.l    ev_line,a0
  5844.         move.b    #'$',(a0)+
  5845.         moveq    #8,d1
  5846.         bsr    conv_hex
  5847.         addq.l    #8,a0
  5848.         moveq    #$20,d6
  5849.         move.b    d6,(a0)+
  5850.  
  5851.         moveq    #10,d1
  5852.         bsr    conv_dec
  5853.  
  5854.         move.b    d6,(a0)+
  5855.         move.b    #'"',(a0)+
  5856.         moveq    #0,d1
  5857.         lea.l    ascIIx,a1
  5858.         rol.l    #8,d0
  5859.         move.b    d0,d1
  5860.         move.b    (a1,d1.w),(a0)+
  5861.         rol.l    #8,d0
  5862.         move.b    d0,d1
  5863.         move.b    (a1,d1.w),(a0)+
  5864.         rol.l    #8,d0
  5865.         move.b    d0,d1
  5866.         move.b    (a1,d1.w),(a0)+
  5867.         rol.l    #8,d0
  5868.         move.b    d0,d1
  5869.         move.b    (a1,d1.w),(a0)+
  5870.         move.b    #'"',(a0)+
  5871.  
  5872.         move.b    d6,(a0)+
  5873.  
  5874.         move.b    #'%',(a0)+
  5875.         moveq    #4-1,d2
  5876. .loop3        moveq    #8-1,d1
  5877. .loop2        addx.l    d0,d0
  5878.         bcc.b    .zero
  5879.         move.b    #'1',(a0)+
  5880.         bra.b    .un
  5881. .zero        move.b    #'0',(a0)+
  5882. .un        dbf    d1,.loop2
  5883.         move.b    #'.',(a0)+
  5884.         dbf    d2,.loop3
  5885.         subq.l    #1,a0
  5886.         move.b    #$a,(a0)+
  5887.         clr.b    (a0)+
  5888.  
  5889.         lea.l    ev_line,a0
  5890.         bsr    print
  5891.  
  5892.         bra.w    end_command
  5893.  
  5894. ;-------------- direct keyboard read (without IRQ) -------
  5895.  
  5896. ;<- dkey
  5897.  
  5898. get_dkey    movem.l    d0-d2,-(a7)
  5899.         move.b    $bfed01,d0
  5900.         btst    #3,d0
  5901.         beq.b    no_dkey
  5902.         move.b    $bfec01,d0
  5903.         not.b    d0
  5904.         ror.b    #1,d0
  5905.         bset    #6,$bfee01
  5906.         cmp.b    #$78,d0
  5907.         beq.w    go_reset
  5908.         moveq    #8-1,d1
  5909. .wait        move.b    6(a6),d2
  5910. .ras        cmp.b    6(a6),d2
  5911.         beq.b    .ras
  5912.         dbf    d1,.wait
  5913.         bclr    #6,$bfee01
  5914.         move.b    d0,dkey
  5915. no_dkey        movem.l    (a7)+,d0-d2
  5916.         rts
  5917.  
  5918. ;-------------- show registres (R) --------------
  5919. cmd_r
  5920. seek_reg    move.b    (a0)+,d0
  5921.         beq.w    end_chg_reg
  5922.         cmp.b    #$20,d0
  5923.         beq.b    seek_reg
  5924.         subq.l    #1,a0
  5925.  
  5926.         bsr    read_reg    ;read registre (no of reg in d0)
  5927.         move.w    d0,d5        ;save no registre in d5
  5928.         bmi.w    illegal_reg
  5929.  
  5930. seek_reg_val    move.b    (a0)+,d0
  5931.         beq.w    illegal_val
  5932.         cmp.b    #$20,d0
  5933.         beq.b    seek_reg_val
  5934.         subq.l    #1,a0
  5935.  
  5936.         bsr    evaluate
  5937.         bne.w    illegal_val
  5938.  
  5939.         cmp.w    #16,d5
  5940.         blt.b    ok_simple_reg
  5941. ;-----------------------------------------------
  5942.         bne.b    no_pc_chg
  5943.         move.l    d0,pc_reg
  5944.         bra.b    end_chg_reg
  5945. ;-----------------------------------------------
  5946. no_pc_chg    cmp.w    #19,d5
  5947.         bne.b    no_usp_chg
  5948.         move.l    d0,usp_reg
  5949. ;-----------------------------------------------
  5950. no_usp_chg    cmp.w    #20,d5
  5951.         bne.b    no_ssp_chg
  5952.         move.l    d0,ssp_reg
  5953. ;-----------------------------------------------
  5954. no_ssp_chg    cmp.w    #17,d5
  5955.         bne.b    no_sr_chg
  5956.         move.w    d0,sr_reg
  5957.         bra.b    end_chg_reg
  5958. ;-----------------------------------------------
  5959. no_sr_chg    cmp.w    #18,d5
  5960.         bne.b    no_vbr_chg
  5961.         move.l    d0,vbr_reg
  5962.         bra.b    end_chg_reg
  5963. ;-----------------------------------------------
  5964. no_vbr_chg    cmp.w    #21,d5
  5965.         bne.b    no_cacr_chg
  5966.         move.l    d0,cacr_reg
  5967.         bra.b    end_chg_reg
  5968. ;-----------------------------------------------
  5969. no_cacr_chg    cmp.w    #22,d5
  5970.         bne.b    no_pcr_chg
  5971.         move.l    d0,msp_reg
  5972.         bra.b    end_chg_reg
  5973. ;-----------------------------------------------
  5974. no_pcr_chg    cmp.w    #23,d5
  5975.         bne.b    no_busr_chg
  5976.         move.l    d0,caar_reg
  5977.         bra.b    end_chg_reg
  5978. ;-----------------------------------------------
  5979. no_busr_chg
  5980.         bra.b    end_chg_reg
  5981.  
  5982. ok_simple_reg    lea.l    registres,a0
  5983.         lsl.w    #2,d5
  5984.         move.l    d0,(a0,d5.w)
  5985.  
  5986. end_chg_reg    bsr    print_reg
  5987.         bra.w    end_command
  5988.  
  5989. ;-------------- print all registres -------------
  5990.  
  5991. print_reg    movem.l    d0-d1/a0-a1/a4,-(a7)
  5992.         moveq    #8,d1
  5993.         lea.l    registres,a1
  5994.         move.l    (a1)+,d0
  5995.         lea.l    data0_reg+3,a0
  5996.         bsr    conv_hex
  5997.         move.l    (a1)+,d0
  5998.         lea.l    data0_reg+3+9,a0
  5999.         bsr    conv_hex
  6000.         move.l    (a1)+,d0
  6001.         lea.l    data0_reg+3+18,a0
  6002.         bsr    conv_hex
  6003.         move.l    (a1)+,d0
  6004.         lea.l    data0_reg+3+27,a0
  6005.         bsr    conv_hex
  6006.         move.l    (a1)+,d0
  6007.         lea.l    data4_reg,a0
  6008.         bsr    conv_hex
  6009.         move.l    (a1)+,d0
  6010.         lea.l    data4_reg+9,a0
  6011.         bsr    conv_hex
  6012.         move.l    (a1)+,d0
  6013.         lea.l    data4_reg+18,a0
  6014.         bsr    conv_hex
  6015.         move.l    (a1)+,d0
  6016.         lea.l    data4_reg+27,a0
  6017.         bsr    conv_hex
  6018.  
  6019.         move.l    (a1)+,d0
  6020.         lea.l    addr0_reg+3,a0
  6021.         bsr    conv_hex
  6022.         move.l    (a1)+,d0
  6023.         lea.l    addr0_reg+3+9,a0
  6024.         bsr    conv_hex
  6025.         move.l    (a1)+,d0
  6026.         lea.l    addr0_reg+3+18,a0
  6027.         bsr    conv_hex
  6028.         move.l    (a1)+,d0
  6029.         lea.l    addr0_reg+3+27,a0
  6030.         bsr    conv_hex
  6031.         move.l    (a1)+,d0
  6032.         lea.l    addr4_reg,a0
  6033.         bsr    conv_hex
  6034.         move.l    (a1)+,d0
  6035.         lea.l    addr4_reg+9,a0
  6036.         bsr    conv_hex
  6037.         move.l    (a1)+,d0
  6038.         lea.l    addr4_reg+18,a0
  6039.         bsr    conv_hex
  6040.         move.l    (a1)+,d0
  6041.         lea.l    addr4_reg+27,a0
  6042.         bsr    conv_hex
  6043.  
  6044.         move.l    pc_reg,d0
  6045.         lea.l    pc_txt+3,a0
  6046.         bsr    conv_hex
  6047.         move.l    ssp_reg,d0
  6048.         lea.l    ssp_txt+4,a0
  6049.         bsr    conv_hex
  6050.         move.l    usp_reg,d0
  6051.         lea.l    usp_txt+4,a0
  6052.         bsr    conv_hex
  6053.         move.l    vbr_reg,d0
  6054.         lea.l    vbr_txt+4,a0
  6055.         bsr    conv_hex
  6056.  
  6057.         move.l    cacr_reg,d0
  6058.         lea.l    CACR_txt+5,a0
  6059.         bsr    conv_hex
  6060.         move.l    caar_reg,d0
  6061.         lea.l    CAAR_txt+5,a0
  6062.         bsr    conv_hex
  6063.         move.l    msp_reg,d0
  6064.         lea.l    MSP_txt+4,a0
  6065.         bsr    conv_hex
  6066.         move.l    isp_reg,d0
  6067.         lea.l    ISP_txt+4,a0
  6068.         bsr    conv_hex
  6069.  
  6070.         lea.l    sr_txt+3,a0
  6071.         moveq    #4,d1
  6072.         move.w    sr_reg,d0
  6073.         bsr    conv_hex
  6074.  
  6075.         move.l    a7_reg,a0
  6076.         and.w    #$2000,d0
  6077.         beq.b    no_superv_stack
  6078.         addq.l    #6,a0
  6079.         move.l    a0,a4
  6080.         bsr    corr_addr
  6081.         move.w    (a4),d0            ;stack frame
  6082.         lsr.w    #4,d0
  6083.         lsr.w    #8,d0
  6084.         add.w    d0,d0
  6085.         lea.l    frame,a4
  6086.         add.w    (a4,d0.w),a0
  6087. no_superv_stack    move.l    pc_reg,a4
  6088.         bsr    corr_addr
  6089.         move.b    #'S',rts_txt+2
  6090.         cmp.w    #$4e73,(a4)        ;cmp if RTE
  6091.         bne.b    no_rte
  6092.         addq.l    #2,a0            ;jmp SR for RTE
  6093.         move.b    #'E',rts_txt+2
  6094. no_rte        move.l    a0,a4
  6095.         bsr    corr_addr
  6096.         move.l    (a4),d0            ;read RTS address
  6097.         lea.l    rts_txt+4,a0
  6098.         moveq    #8,d1
  6099.         bsr    conv_hex
  6100.  
  6101.         lea.l    registre_txt,a0
  6102.         bsr    print
  6103.  
  6104.         jsr    init_regBMON
  6105.  
  6106.         movem.l    (a7)+,d0-d1/a0-a1/a4
  6107.         rts
  6108.  
  6109. frame        dc.w 2,2,6,2,2,2,2,2,22,14,24,40,2,2,2 ;all stack frame size
  6110.  
  6111.  
  6112. ********************************************************************
  6113. ;-------------- print single instruction at dis_ptr  ---------------
  6114.  
  6115. ;d0 returns instruction len
  6116.  
  6117. single_inst    movem.l    d1-d7/a0-a4,-(a7)
  6118.  
  6119.         move.l    dis_ptr,a4
  6120.         bsr    corr_addr
  6121.  
  6122.         lea.l    general_txt,a0
  6123.         moveq    #7,d0        ;upper case, d $address, indir. address
  6124.         bsr    disassemble
  6125.         lea.l    general_txt,a0
  6126.         bsr    print
  6127.  
  6128.         movem.l    (a7)+,d1-d7/a0-a4
  6129.         rts
  6130.  
  6131. ***************************************************************
  6132. ;-------------- hex dump (H) ---------------------
  6133.  
  6134. cmd_h        moveq    #0,d1
  6135. seek_para_h    move.b    (a0)+,d0
  6136.         beq.w    ok_h_cmd        ;keep last address
  6137.         cmp.b    #$20,d0
  6138.         beq.b    seek_para_h
  6139.         subq.l    #1,a0
  6140.  
  6141.         bsr    evaluate        ;returns address in d0
  6142.         bne.w    illegal_addr
  6143.         move.l    d0,hex_ptr
  6144.  
  6145.         move.l    d0,a3
  6146.  
  6147. .loop        move.b    (a0)+,d0
  6148.         beq.w    ok_h_cmd
  6149.         cmp.b    #"'",d0
  6150.         beq.b    ok_h_ascII
  6151.         cmp.b    #$20,d0
  6152.         beq.b    .loop
  6153.         subq.l    #1,a0
  6154.         st    label
  6155.         move.w    #1,eval_size    ;set .W par default
  6156.         bsr    evaluate
  6157.         beq.b    .oky
  6158.         sf    label
  6159.         bra.w    illegal_val
  6160. .oky        sf    label
  6161.         move.l    a3,a4
  6162.         bsr    corr_addr
  6163.         move.w    eval_size,d2
  6164. .next        move.b    d0,(a4,d2.w)
  6165.         lsr.l    #8,d0
  6166.         addq.l    #1,a3
  6167.         dbf    d2,.next
  6168.         st    d1
  6169.         bra.b    .loop
  6170.  
  6171. ok_h_ascII    tst.b    d1
  6172.         bne.b    ok_h_cmd
  6173.         move.l    hex_ptr,a3
  6174. .loop        move.b    (a0)+,d0
  6175.         beq.b    ok_h_cmd
  6176.         cmp.b    #"'",d0
  6177.         beq.b    ok_h_cmd
  6178.         move.l    a3,a4
  6179.         bsr    corr_addr
  6180.         move.b    d0,(a4)
  6181.         st    d1
  6182.         addq.l    #1,a3
  6183.         bra.b    .loop
  6184.  
  6185. ok_h_cmd    tst.b    d1
  6186.         bne.w    end_command
  6187.         move.l    hex_ptr,a4        ;a4=mem ptr
  6188.         move.l    a4,d0
  6189.  
  6190.         moveq    #8-1,d3            ;print 8 lines
  6191.         moveq    #15,d5
  6192.  
  6193. .loop2        bsr    make_hex_line
  6194.  
  6195.         lea.l    16(a4),a4
  6196.         lea.l    hex_txt,a0
  6197.         bsr    print
  6198.  
  6199.         tst.b    break
  6200.         dbne    d3,.loop2
  6201.  
  6202.         move.l    a4,hex_ptr
  6203.  
  6204.         bra.w    end_command
  6205.  
  6206. ;-------------- up arrow cmd ---------------
  6207.  
  6208. ;-> d2 = scroll step (1 or SC_STEP)
  6209.  
  6210. cmdu_h        move.l    ascII_ptr,a0
  6211.         move.w    d2,d0
  6212.         mulu    #80,d0
  6213.         add.l    d0,a0
  6214.         cmp.w    #'h ',(a0)    ;last top line was an hex dump ?
  6215.         bne.b    .noh
  6216.         addq.l    #2,a0
  6217.         bsr    evaluate    ;get last address
  6218.         move.l    d2,d1
  6219.         lsl.l    #4,d1        ;*16
  6220.         sub.l    d1,d0
  6221.         move.l    d0,a4
  6222.  
  6223.         subq.w    #1,d2
  6224. .print        bsr    make_hex_line
  6225.         lea.l    16(a4),a4
  6226.         lea.l    hex_txt,a0
  6227.         bsr    print
  6228.         dbf    d2,.print
  6229.  
  6230.         clr.w    2(a3)
  6231. ;        lea.l    hex_txt2,a1
  6232. ;        move.b    #$d,18(a1)
  6233. ;        move.b    #$a,18(a1)
  6234.  
  6235.         moveq    #0,d0
  6236.  
  6237. .noh        rts
  6238.  
  6239. ;-------------- down arrow cmd -------------
  6240.  
  6241. cmdd_h        move.l    ascII_ptr,a0
  6242.         move.w    window_bot,d0
  6243.         subq.w    #1,d0
  6244.         sub.w    d2,d0
  6245.         mulu    #80,d0
  6246.         add.l    d0,a0
  6247.         cmp.w    #'h ',(a0)    ;last line was an hex dump ?
  6248.         bne.b    .noh
  6249.         addq.l    #2,a0
  6250.         bsr    evaluate    ;get last address
  6251.         add.l    #16,d0
  6252.         move.l    d0,a4
  6253.  
  6254.         sub.w    d2,(2,a3)
  6255.  
  6256.         subq.w    #1,d2
  6257. .print        bsr    make_hex_line
  6258.         lea.l    hex_txt,a0
  6259.         bsr    print
  6260.         lea.l    16(a4),a4
  6261.         dbf    d2,.print
  6262.  
  6263.         move.l    a4,hex_ptr
  6264.  
  6265.         moveq    #0,d0
  6266.  
  6267. .noh        rts
  6268.  
  6269.  
  6270. ;-> a4=address to dump
  6271. ;<- hex_txt is filled with the dump text
  6272.  
  6273. make_hex_line    movem.l    d0-a4,-(a7)
  6274.         moveq    #$0f,d5
  6275.  
  6276.         move.l    a4,d0
  6277.         bsr    corr_addr
  6278.  
  6279.         lea.l    ascIIx,a1
  6280.         lea.l    hex_list,a3
  6281.  
  6282.         lea.l    hex_txt+3,a0    ;print address
  6283.         moveq    #8,d1
  6284.         bsr    conv_hex
  6285.  
  6286.         lea.l    hex_txt+3+8+2,a0        ;long list
  6287.         lea.l    hex_txt2+1,a2        ;ascII print
  6288.         moveq    #2,d1                ;2 for conv_hex
  6289.         moveq    #0,d0
  6290.         moveq    #8-1,d6
  6291. .loopb        moveq    #2-1,d2
  6292. .loop        move.b    (a4)+,d0
  6293.         move.b    (a1,d0.w),(a2)+
  6294.         move.w    d0,d4
  6295.         and.w    d5,d4
  6296.         lsr.w    #4,d0
  6297.         move.b    (a3,d0.w),(a0)+
  6298.         move.b    (a3,d4.w),(a0)+
  6299.         dbf    d2,.loop
  6300.         addq.l    #2,a0
  6301.         dbf    d6,.loopb
  6302.  
  6303.         movem.l    (a7)+,d0-a4
  6304.         rts
  6305.  
  6306. ***************************************************************
  6307. ;-------------- ascII dump (n) ---------------------
  6308. cmd_n
  6309. seek_para_n    move.b    (a0)+,d0
  6310.         beq.b    ok_n_cmd        ;keep last address
  6311.         cmp.b    #$20,d0
  6312.         beq.b    seek_para_n
  6313.         subq.l    #1,a0
  6314.  
  6315.         bsr    evaluate        ;returns address in d0
  6316.         bne.w    illegal_addr
  6317.         move.l    d0,asc_ptr
  6318.  
  6319. ok_n_cmd    move.l    asc_ptr,a4        ;a4=mem ptr
  6320.         move.l    a4,d0
  6321.  
  6322.         moveq    #8-1,d3            ;print 8 lines
  6323.  
  6324. .loop2        moveq    #$a,d0
  6325.         bsr    make_ascII_line
  6326.  
  6327.         lea.l    general_txt,a0
  6328.         bsr    print
  6329.         lea.l    64(a4),a4
  6330.  
  6331.         tst.b    break
  6332.         dbne    d3,.loop2
  6333.  
  6334.         move.l    a4,asc_ptr
  6335.  
  6336.         bra.w    end_command
  6337.  
  6338. ;-------------- scroll up ascII dump ----------------------
  6339.  
  6340. cmdu_n        move.l    ascII_ptr,a0
  6341.         move.w    d2,d0
  6342.         mulu    #80,d0
  6343.         add.l    d0,a0
  6344.         cmp.w    #'n ',(a0)    ;last top line was an ascII dump ?
  6345.         bne.b    .non
  6346.         addq.l    #2,a0
  6347.         bsr    evaluate    ;get last address
  6348.         move.l    d2,d1
  6349.         lsl.l    #6,d1        ;*64
  6350.         sub.l    d1,d0
  6351.         move.l    d0,a4
  6352.  
  6353.         subq.w    #1,d2
  6354.  
  6355. .print        moveq    #$a,d0
  6356.         bsr    make_ascII_line
  6357.  
  6358.         lea.l    general_txt,a0
  6359.         bsr    print
  6360.  
  6361.         lea.l    64(a4),a4
  6362.  
  6363.         dbf    d2,.print
  6364.  
  6365.         clr.w    (2,a3)
  6366.  
  6367.         moveq    #0,d0
  6368.  
  6369. .non        rts
  6370.  
  6371. ;-------------- scroll down ascII dump --------------------
  6372.  
  6373. cmdd_n        move.l    ascII_ptr,a0
  6374.         move.w    window_bot,d0
  6375.         subq.w    #1,d0
  6376.         sub.w    d2,d0
  6377.         mulu    #80,d0
  6378.         add.l    d0,a0
  6379.         cmp.w    #'n ',(a0)    ;last line was an ascII dump ?
  6380.         bne.b    .non
  6381.         addq.l    #2,a0
  6382.         bsr    evaluate    ;get last address
  6383.         add.l    #64,d0
  6384.         move.l    d0,a4
  6385.  
  6386.         sub.w    d2,(2,a3)
  6387.  
  6388.         subq.w    #1,d2
  6389.  
  6390. .print        moveq    #$a,d0
  6391.         bsr    make_ascII_line
  6392.  
  6393.         lea.l    general_txt,a0
  6394.         bsr    print
  6395.  
  6396.         lea.l    64(a4),a4
  6397.  
  6398.         dbf    d2,.print
  6399.  
  6400.         move.l    a4,asc_ptr
  6401.  
  6402.  
  6403.         moveq    #0,d0
  6404.  
  6405. .non        rts
  6406.  
  6407.  
  6408. ;-> a4=mem ptr
  6409. ;-> d0=end line ascII ($a or $d)
  6410. ;<- general_txt filled with ascII line
  6411.  
  6412. make_ascII_line    movem.l    d0-a4,-(a7)
  6413.         move.b    d0,d7
  6414.         lea.l    ascIIx,a1
  6415.         move.l    a4,d0
  6416.         bsr    corr_addr
  6417.  
  6418.         lea.l    general_txt,a0
  6419.         move.b    #'n',(a0)+
  6420.         move.b    #' ',(a0)+
  6421.         move.b    #'$',(a0)+
  6422.         moveq    #8,d1
  6423.         bsr    conv_hex
  6424.  
  6425.         lea.l    8(a0),a0
  6426.         move.b    #' ',(a0)+
  6427.         moveq    #0,d0
  6428.         moveq    #64-1,d2
  6429. .loop        move.b    (a4)+,d0
  6430.         move.b    (a1,d0.w),(a0)+
  6431.         dbf    d2,.loop
  6432.  
  6433.         move.b    d7,(a0)+
  6434.         sf    (a0)+
  6435.  
  6436.         movem.l    (a7)+,d0-a4
  6437.         rts
  6438.  
  6439.  
  6440. *********************************************************************
  6441. ;correct address to access, to make the screen mem of AR transparent.
  6442.  
  6443. ;-> a4=address to correct
  6444. ;<- a4=address corrected
  6445. ;<- corr_val=offset to add to get the corrected address
  6446.  
  6447. corr_addr:    clr.l    corr_val
  6448.         cmpa.l    #LOSIZE-64,a4
  6449.         bge.b    .ok_hex_low
  6450.         add.l    #backup_pic,a4
  6451.         move.l    #backup_pic,corr_val
  6452. .ok_hex_low    rts
  6453.  
  6454.  
  6455. ***************************************************
  6456. ;-------------- trace mode ------------------------
  6457. cmd_t        move.b    (a0)+,d0
  6458.         beq.w    single_trace
  6459.         cmp.b    #$20,d0
  6460.         beq.b    cmd_t
  6461.         bsr    upper_case
  6462.         cmp.b    #'A',d0
  6463.         bne.b    no_trace_a
  6464. ;-------------- trace till address reached -----
  6465. seek_tracea    move.b    (a0)+,d0
  6466.         beq.w    illegal_addr
  6467.         cmp.b    #$20,d0
  6468.         beq.b    seek_tracea
  6469.         subq.l    #1,a0
  6470.         bsr    evaluate
  6471.         bne.w    illegal_addr
  6472.         btst    #0,d0
  6473.         bne.w    illegal_addr
  6474.         move.l    d0,trace_address
  6475.         st    escape
  6476.         bra.w    end_command
  6477. ;-------------- trace x steps -----------
  6478. no_trace_a    subq.l    #1,a0
  6479.         bsr    evaluate
  6480.         bne.w    illegal_val
  6481.         tst.l    d0
  6482.         beq.w    illegal_val
  6483.         cmp.l    #$10000,d0
  6484.         bge.w    illegal_val
  6485. init_trace    move.w    d0,trace_count
  6486.         st    escape
  6487.         bra.w    end_command
  6488.  
  6489. single_trace    moveq    #1,d0
  6490.         bra.b    init_trace
  6491.  
  6492. ;---------------------------------------
  6493. trace_reach    move.l    a0,-(a7)
  6494.         lea.l    trace_count,a0
  6495.         subq.w    #1,(a0)
  6496.         beq.b    end_trace_mode
  6497.         move.l    (a7)+,a0
  6498.         or.w    #$8000,(a7)
  6499.         rte
  6500. end_trace_mode    move.l    vbr_reg,a0
  6501.         move.l    old_trace,$24(a0)
  6502.         move.l    (a7)+,a0
  6503.         and.w    #$7fff,(a7)
  6504.         bra.w    monitor
  6505. ;---------------------------------------------
  6506. tracea_reach    move.l    d0,-(a7)
  6507.         move.l    trace_address,d0
  6508.         cmp.l    2+4(a7),d0
  6509.         beq.b    end_tracea
  6510.         move.l    (a7)+,d0
  6511.         or.w    #$8000,(a7)
  6512.         rte
  6513. end_tracea    move.l    (a7)+,d0
  6514.         move.l    a0,-(a7)
  6515.         move.l    vbr_reg,a0
  6516.         move.l    old_trace,$24(a0)
  6517.         lea.l    trace_address,a0
  6518.         move.l    #-1,(a0)
  6519.         move.l    (a7)+,a0
  6520.         and.w    #$7fff,(a7)
  6521.         bra.w    monitor
  6522.  
  6523. ***************************************************
  6524. ;-------------- copy memory -----------------------
  6525. ;-------------- and exg (CE) memory ---------------
  6526.  
  6527. cmd_c        move.b    (a0),d0
  6528.         bsr    upper_case
  6529.         sf    exgc
  6530.         cmp.b    #'E',d0
  6531.         bne.b    no_exgc
  6532.         st    exgc
  6533.         addq.l    #1,a0
  6534.  
  6535. no_exgc        move.b    (a0)+,d0
  6536.         beq.w    illegal_addr
  6537.         cmp.b    #$20,d0
  6538.         beq.b    no_exgc
  6539.         subq.l    #1,a0
  6540.         bsr    evaluate
  6541.         bne.w    illegal_addr
  6542.         move.l    d0,copy_start
  6543.  
  6544. seek_end_copy    move.b    (a0)+,d0
  6545.         beq.w    illegal_addr
  6546.         cmp.b    #$20,d0
  6547.         beq.b    seek_end_copy
  6548.         subq.l    #1,a0
  6549.  
  6550.         bsr    evaluate
  6551.         bne.w    illegal_addr
  6552.         move.l    d0,copy_end
  6553.  
  6554. seek_dest_copy    move.b    (a0)+,d0
  6555.         beq.w    illegal_addr
  6556.         cmp.b    #$20,d0
  6557.         beq.b    seek_dest_copy
  6558.         subq.l    #1,a0
  6559.  
  6560.         bsr    evaluate
  6561.         bne.w    illegal_addr
  6562.         move.l    d0,copy_dest
  6563.  
  6564.         movem.l    copy_start,d0-d1
  6565.         sub.l    d0,d1                ;length
  6566.         move.l    copy_dest,d0
  6567.         add.l    d0,d1
  6568.         movem.l    copy_start,d0-d1
  6569.         cmp.l    d0,d1
  6570.         ble.w    illegal_addr            ;if end<start
  6571.  
  6572.         move.l    d0,a0
  6573.         move.l    d1,a2
  6574.         move.l    copy_dest,a1
  6575.  
  6576.         bsr    remove_pic
  6577.  
  6578.         moveq    #0,d0
  6579.         move.l    d0,$180(a6)
  6580.  
  6581.         tst.b    exgc
  6582.         beq.b    do_copy_mem
  6583.  
  6584. do_copye_mem    move.b    (a0),d0
  6585.         move.b    (a1),(a0)+
  6586.         move.b    d0,(a1)+
  6587.         cmp.l    a2,a0
  6588.         blt.b    do_copye_mem
  6589.         bra.b    end_copy
  6590.  
  6591. do_copy_mem    move.b    (a0)+,(a1)+
  6592.         cmp.l    a2,a0
  6593.         blt.b    do_copy_mem
  6594.  
  6595. end_copy    bsr    set_pic
  6596.  
  6597.         bra.w    end_command
  6598.  
  6599. ***************************************************
  6600. ;-------------- break point set -------------------
  6601. cmd_b        move.b    (a0)+,d0
  6602.         beq.w    illegal_addr
  6603.         bsr    upper_case
  6604.         moveq    #0,d7
  6605.         cmp.b    #'J',d0
  6606.         bne.w    no_jmp_break
  6607.         moveq    #-1,d7            ;jsr break mode on
  6608.         bra.b    seek_break
  6609.  
  6610. no_jmp_break    cmp.b    #'D',d0
  6611.         bne.b    no_del_break
  6612.         lea.l    break_list,a0
  6613.         moveq    #-1,d0
  6614. do_clr_all_BP    tst.l    (a0)
  6615.         bmi.b    cleared_all_BP
  6616.         clr.l    (a0)
  6617.         move.w    d0,4(a0)
  6618.         move.l    d0,6(a0)
  6619.         lea.l    10(a0),a0
  6620.         bra.b    do_clr_all_BP
  6621. cleared_all_BP    lea.l    all_BP_txt,a0
  6622.         bsr    print
  6623.         bra.w    end_command
  6624. ;-------------------------------------------
  6625.  
  6626. no_del_break    subq.l    #1,a0
  6627. seek_break    move.b    (a0)+,d0
  6628.         beq.w    print_break
  6629.         cmp.b    #$20,d0
  6630.         beq.b    seek_break
  6631.         subq.l    #1,a0
  6632.  
  6633.         bsr    evaluate
  6634.         bne.w    illegal_addr
  6635.         btst    #0,d0
  6636.         bne.w    illegal_addr
  6637.         move.l    d0,a2
  6638.  
  6639. ;-------------- check if clear BP command ------------
  6640.         lea.l    break_list,a1
  6641. seek_clear_BP    tst.l    (a1)
  6642.         bmi.b    end_clear_BP
  6643.         cmp.l    (a1),a2
  6644.         beq.b    pre_clear_BP
  6645.         lea.l    10(a1),a1
  6646.         bra.b    seek_clear_BP
  6647. pre_clear_BP    cmp.w    #-1,4(a1)
  6648.         bne.w    do_clear_BP
  6649.         lea.l    10(a1),a1
  6650.         bra.b    seek_clear_BP
  6651.  
  6652. ;-------------- add BP to list -----------------------
  6653.  
  6654. end_clear_BP    lea.l    break_list,a1
  6655. seek_free_break    tst.l    (a1)
  6656.         bmi.w    too_break
  6657.         tst.l    (a1)
  6658.         bne.b    break_used
  6659.         cmp.w    #-1,4(a1)
  6660.         beq.b    ok_break
  6661. break_used    lea.l    10(a1),a1
  6662.         bra.b    seek_free_break
  6663.  
  6664. ok_break    tst.l    d7
  6665.         beq.b    no_jsrb_set
  6666.         move.l    a2,(a1)            ;save address
  6667.         move.l    a2,a4
  6668.         bsr    corr_addr
  6669.         move.w    (a4),4(a1)        ;save instr.
  6670.         move.l    2(a4),6(a1)        ;save param.
  6671.         moveq    #8,d1
  6672.         move.l    a2,d0
  6673.         lea.l    BPJ_set_txt,a0
  6674.         bsr    print
  6675.         bsr    print_hexCR
  6676.         bra.b    ok_jsrb_set
  6677.  
  6678. no_jsrb_set    move.l    a2,(a1)
  6679.         move.l    a2,a4
  6680.         bsr    corr_addr
  6681.         move.w    (a4),4(a1)        ;save instr.
  6682.  
  6683.         moveq    #8,d1
  6684.         move.l    a2,d0
  6685.         lea.l    BP_set_txt,a0
  6686.         bsr    print
  6687.         bsr    print_hexCR
  6688.  
  6689. ok_jsrb_set
  6690.         bra.w    end_command
  6691. ;-------------- do clear BP command -----------------------
  6692.  
  6693. do_clear_BP    move.w    4(a1),(a2)
  6694.         clr.l    (a1)
  6695.         move.l    6(a1),d0
  6696.         cmp.l    #-1,d0
  6697.         beq.b    no_jsrb_clr
  6698.         move.l    d0,2(a2)
  6699. no_jsrb_clr    move.l    #-1,6(a1)
  6700.         move.w    #-1,4(a1)
  6701.         moveq    #8,d1
  6702.         move.l    a2,d0
  6703.         lea.l    BP_clr_txt,a0
  6704.         bsr    print
  6705.         bsr    print_hexCR
  6706.         bra.w    end_command
  6707.  
  6708. ;-------------- init break points when exiting AR -------------
  6709. init_break    movem.l    d0-d2/a0-a2,-(a7)
  6710.         sf    break_mode
  6711.         sf    BP_reach
  6712.         sf    BPJ_reach
  6713.         sf    BPatPC
  6714.         lea.l    break_list,a0
  6715. set_BP        tst.l    (a0)
  6716.         bmi.b    end_set_BP
  6717.         bne.b    set_break
  6718.         cmp.w    #-1,4(a0)
  6719.         bne.b    set_break
  6720.         lea.l    10(a0),a0
  6721.         bra.b    set_BP
  6722. set_break    cmp.l    #-1,6(a0)
  6723.         beq.b    no_BJSR_set
  6724.         move.l    (a0),a1
  6725.         move.w    #$4eb9,(a1)        ;JSR
  6726.         lea.l    JSR_reach,a2
  6727.         move.l    a2,2(a1)
  6728.         st    no_kill            ;don't kill AR on exit
  6729.         bra.b    end_BJ_set
  6730. no_BJSR_set    move.l    (a0),a1
  6731.         cmp.l    pc_reg,a1
  6732.         bne.b    .notpc
  6733.         st    BPatPC
  6734.         move.w    #1,trace_count
  6735.         bra.b    end_BJ_set
  6736. .notpc        move.w    #$4afc,(a1)
  6737.         st    no_kill            ;don't kill AR on exit
  6738.         st    break_mode
  6739. end_BJ_set    lea.l    10(a0),a0
  6740.         bra.b    set_BP
  6741. end_set_BP    tst.b    break_mode
  6742.         beq.b    no_break_mode
  6743.         move.l    vbr_reg,a0
  6744.         move.l    $10(a0),illegal_except
  6745.         lea.l    break_reach,a2
  6746.         move.l    a2,$10(a0)
  6747. no_break_mode    movem.l    (a7)+,d0-d2/a0-a2
  6748.         rts
  6749.  
  6750. ;-------------- remove all breakpoints from mem. -----
  6751. clear_break    movem.l    a0-a1,-(a7)
  6752.         lea.l    break_list,a0
  6753. do_clr_BP    tst.l    (a0)
  6754.         bmi.w    end_clear_BPa
  6755.         bne.b    ok_clr_BP
  6756.         cmp.w    #-1,4(a0)
  6757.         beq.b    no_clr_BP
  6758. ok_clr_BP    move.l    (a0),a1
  6759.         move.w    4(a0),(a1)
  6760.         cmp.l    #-1,6(a0)
  6761.         beq.b    no_clr_BP
  6762.         move.l    6(a0),2(a1)
  6763. no_clr_BP    lea.l    10(a0),a0
  6764.         bra.b    do_clr_BP
  6765. end_clear_BPa    movem.l    (a7)+,a0-a1
  6766.         rts
  6767.  
  6768. ;----------------------------------------------
  6769.  
  6770. break_reach    movem.l    a0-a1/a5,-(a7)
  6771.         move.l    2+12(a7),a0        ;fetch PC
  6772.         sf    BP_reach
  6773.         lea.l    break_list,a1
  6774. seek_BP_reach    tst.l    (a1)
  6775.         bmi.b    break_not_found
  6776.         bne.b    do_check_BP
  6777.         cmp.w    #-1,4(a1)
  6778.         beq.b    no_check_BP
  6779. do_check_BP    cmp.l    (a1),a0
  6780.         beq.b    found_break
  6781. no_check_BP    lea.l    10(a1),a1
  6782.         bra.b    seek_BP_reach
  6783.  
  6784. found_break    move.w    4(a1),(a0)        ;restore old instr.
  6785.         clr.l    (a1)
  6786.         move.w    #-1,4(a1)        ;clear old BP
  6787.         move.l    a0,Break_Address
  6788.         st    BP_reach
  6789.         movem.l    (a7)+,a0-a1/a5
  6790.         bra    monitor            ;enter monitor
  6791.  
  6792. break_not_found    movem.l    (a7)+,a0-a1/a5
  6793.         move.l    illegal_except,-(a7)
  6794.         rts                ;jmp old illegal
  6795.  
  6796. ;----------------------------------------------------------
  6797.  
  6798. JSR_reach    movem.l    a2,-(a7)
  6799.         lea.l    JB_save,a2
  6800.         movem.l    a0-a1,(a2)
  6801.         movem.l    (a7)+,a2
  6802.         movem.l    (a7)+,a0
  6803.         lea.l    Break_Address,a1
  6804.         move.l    a0,(a1)
  6805.         move.l    $80.w,a1
  6806.         lea.l    JB_sup(pc),a0
  6807.         move.l    a0,$80.w
  6808.         trap    #0
  6809. JB_sup        move.l    a1,$80.w
  6810.         move.l    Break_Address,a0    ;fetch break_address
  6811.         subq.l    #6,a0            ;sub len jsr address
  6812.         lea.l    BPJ_reach,a1
  6813.         sf    (a1)
  6814.         lea.l    break_list,a1
  6815. seek_BPJ_reach    tst.l    (a1)
  6816.         bmi.b    bj_not_found
  6817.         bne.b    do_check_BPJ
  6818.         cmp.w    #-1,4(a1)
  6819.         beq.b    no_check_BPJ
  6820. do_check_BPJ    cmp.l    (a1),a0
  6821.         beq.b    found_breakJ
  6822. no_check_BPJ    lea.l    10(a1),a1
  6823.         bra.b    seek_BPJ_reach
  6824.  
  6825. found_breakJ    move.w    4(a1),(a0)        ;restore old instr.
  6826.         move.l    6(a1),2(a0)
  6827.         clr.l    (a1)
  6828.         move.w    #-1,4(a1)        ;clear old BP
  6829.         move.l    #-1,6(a1)
  6830.         move.l    a0,Break_Address
  6831.         st    BPJ_reach
  6832.         movem.l    JB_save,a0-a1
  6833.         move.l    Break_Address,2(a7)
  6834.         bra.w    monitor        ;enter monitor
  6835.  
  6836. bj_not_found    move.l    Break_Address,2(a7)
  6837.         movem.l    JB_save,a0-a1
  6838.         rte
  6839.  
  6840. ;--------------------------------------------------
  6841. print_break    lea.l    break_list,a1
  6842.         moveq    #8,d1
  6843. do_break_all    tst.l    (a1)
  6844.         bmi.b    end_break_all
  6845.         bne.b    ok_break_all
  6846.         cmp.w    #-1,4(a1)
  6847.         beq.b    no_break_all
  6848. ok_break_all    tst.l    6(a1)
  6849.         bmi.b    no_Bjsr_prt
  6850.         move.l    (a1),d0
  6851.         lea.l    all_break2_txt,a0
  6852.         bra.b    ok_Bjsr_prt
  6853.  
  6854. no_Bjsr_prt    move.l    (a1),d0
  6855.         lea.l    all_break_txt,a0
  6856. ok_Bjsr_prt    bsr    print
  6857.         bsr    print_hexCR
  6858.  
  6859. no_break_all    lea.l    10(a1),a1
  6860.         bra.b    do_break_all
  6861.  
  6862. end_break_all    bra.w    end_command
  6863.  
  6864. ***************************************************
  6865. ;-------------- disassemble (D) -------------------
  6866.  
  6867. cmd_d:        move.b    (a0)+,d0
  6868.         beq.b    ok_d_cmd        ;keep last address
  6869.         cmp.b    #$20,d0
  6870.         beq.b    cmd_d
  6871.         subq.l    #1,a0
  6872.  
  6873.         bsr    evaluate
  6874.         bne.w    illegal_addr
  6875.         btst    #0,d0            ;address must be even
  6876.         bne.w    illegal_addr
  6877.         move.l    d0,dis_ptr
  6878.  
  6879. ok_d_cmd    move.l    dis_ptr,d0        ;a4 = ptr on memory
  6880.         and.w    #$fffe,d0        ;even addr.
  6881.         move.l    d0,a4
  6882.  
  6883.         moveq    #8-1,d7
  6884. next_dis_line
  6885.         move.l    a4,-(a7)
  6886.         bsr    corr_addr
  6887.  
  6888.         lea.l    general_txt,a0
  6889.         moveq    #7,d0            ;upper case, d $address
  6890.         bsr    disassemble
  6891.         move.l    (a7)+,a4
  6892.         add.w    d0,a4            ;add instr len
  6893.  
  6894.         lea.l    general_txt,a0
  6895.         bsr    print
  6896.  
  6897.         tst.b    break
  6898.         dbne    d7,next_dis_line
  6899.  
  6900.         move.l    a4,dis_ptr
  6901.  
  6902.         bra.w    end_command
  6903.  
  6904. ;-------------- scroll up disassemble --------
  6905.  
  6906. cmdu_d        move.l    ascII_ptr,a0
  6907.         lea.l    80(a0),a0
  6908.         cmp.w    #'D ',(a0)    ;last top line was a disassemble ?
  6909.         bne.w    .nod
  6910.         addq.l    #2,a0
  6911.         bsr    evaluate    ;get last address
  6912.         move.l    d0,d6        ;d6=address of next instr.
  6913.         move.l    d0,d5
  6914.         sub.l    #20,d5        ;d5=address to test
  6915.  
  6916. .loop        move.l    d5,a4
  6917.         bsr    corr_addr
  6918.         moveq    #7,d0
  6919.         lea.l    general_txt,a0
  6920.         bsr    disassemble
  6921.         add.l    d5,d0
  6922.         cmp.l    d0,d6        ;right len of instr ?
  6923.         beq.b    .ok
  6924.  
  6925.         move.l    d0,d5
  6926.         cmp.l    d6,d5        ;reach end of area to test
  6927.         blt.b    .loop
  6928.  
  6929. ;---- couldn't find an instr. with the right length -> print 'dc.w'
  6930.  
  6931.         lea.l    general_txt,a0
  6932.         move.w    #"D ",(a0)+
  6933.         move.b    #"$",(a0)+
  6934.         move.l    d6,d0
  6935.         subq.l    #2,d0
  6936.         moveq    #8,d1
  6937.         bsr    conv_hex
  6938.         add.l    d1,a0
  6939.         move.b    #" ",(a0)+
  6940.         move.l    #"Dc.W",(a0)+
  6941.         move.w    #" $",(a0)+
  6942.         move.l    d6,a4
  6943.         bsr    corr_addr
  6944.         move.w    (a4),d0
  6945.         moveq    #4,d1
  6946.         bsr    conv_hex
  6947.         add.l    d1,a0
  6948.         move.w    #$0a00,(a0)+
  6949.         bra.w    .ok
  6950.  
  6951. .ok        move.l    d5,d0
  6952.  
  6953.         lea.l    general_txt,a0
  6954.         bsr    print
  6955.         subq.w    #1,(2,a3)        ;cursor one line up
  6956.  
  6957.         moveq    #0,d0
  6958.  
  6959. .nod        rts
  6960.  
  6961. .bad_addr    lea.l    illegal_addr_txt,a0
  6962.         bsr    print
  6963.         bra.b    .nod
  6964.  
  6965. ;-------------- scroll down disassemble ---------
  6966.  
  6967. cmdd_d        move.l    ascII_ptr,a0
  6968.         move.l    d0,-(a7)
  6969.         move.w    window_bot,d0
  6970.         subq.w    #2,d0
  6971.         mulu    #80,d0
  6972.         add.l    d0,a0
  6973.         move.l    (a7)+,d0
  6974.         cmp.w    #'D ',(a0)    ;last line was a disassemble ?
  6975.         bne.b    .nod
  6976.         addq.l    #2,a0
  6977.         bsr    evaluate    ;get last address
  6978.         move.l    d0,d6
  6979.         move.l    d0,a4
  6980.         bsr    corr_addr
  6981.         moveq    #0,d0
  6982.         lea.l    general_txt,a0
  6983.         bsr    disassemble    ;calc last instr size
  6984.         add.l    d6,d0
  6985.         move.l    d0,a4
  6986.         move.l    d0,d6
  6987.         bsr    corr_addr
  6988.         moveq    #7,d0
  6989.         lea.l    general_txt,a0
  6990.         bsr    disassemble
  6991.         add.l    d0,d6            ;add instr. size
  6992.         move.l    d6,dis_ptr        ;next instr. address
  6993.  
  6994.         subq.w    #1,(2,a3)        ;cursor one line up
  6995.         lea.l    general_txt,a0
  6996.         bsr    print
  6997.  
  6998.         moveq    #0,d0
  6999.  
  7000. .nod        rts
  7001.  
  7002.  
  7003.         include src/65816.s
  7004.  
  7005. ***********************************************************
  7006. ;-------------- error routines ---------------------
  7007.  
  7008. illegal_syntax    lea.l    illegal_syntax_txt,a0
  7009.         bsr    print
  7010.         bra.w    end_command
  7011.  
  7012. illegal_val    lea.l    illegal_val_txt,a0
  7013.         bsr    print
  7014.         bra.w    end_command
  7015.  
  7016. illegal_reg    lea.l    illegal_reg_txt,a0
  7017.         bsr    print
  7018.         bra.w    end_command
  7019.  
  7020. illegal_addr    lea.l    illegal_addr_txt,a0
  7021.         bsr    print
  7022.         bra.w    end_command
  7023.  
  7024. illegal_name    lea.l    illegal_name_txt,a0
  7025.         bsr    print
  7026.         bra.w    end_command
  7027.  
  7028. illegal_string    lea.l    illegal_string_txt,a0
  7029.         bsr    print
  7030.         bra.w    end_command
  7031.  
  7032. illegal_expr    lea.l    illegal_expr_txt,a0
  7033.         bsr    print
  7034.         bra.w    end_command
  7035.  
  7036. too_break    lea.l    too_break_txt,a0
  7037.         bsr    print
  7038.         bra.w    end_command
  7039.  
  7040. not_found    lea.l    not_found_txt,a0
  7041.         bsr    print
  7042.         bra.w    end_command
  7043.  
  7044. *********************************************************
  7045. ;d0=ascII
  7046. upper_case:    cmp.b    #'a',d0            ;switch to upper case (d0)
  7047.         blt.b    .ok_upper
  7048.         cmp.b    #'z',d0
  7049.         bgt.b    .ok_upper
  7050.         add.b    #'A'-'a',d0
  7051. .ok_upper    rts
  7052.  
  7053. ;d0=ascII
  7054. lower_case    cmp.b    #'A',d0            ;switch to lower case (d0)
  7055.         blt.b    .ok_lower
  7056.         cmp.b    #'Z',d0
  7057.         bgt.b    .ok_lower
  7058.         add.b    #'a'-'A',d0
  7059. .ok_lower    rts
  7060.  
  7061. ;d1=ascII
  7062. upper_case1    cmp.b    #'a',d1            ;switch to upper case (d1)
  7063.         blt.b    .ok_upper
  7064.         cmp.b    #'z',d1
  7065.         bgt.b    .ok_upper
  7066.         add.b    #'A'-'a',d1
  7067. .ok_upper    rts
  7068.  
  7069. ************************************************************
  7070. ;read string at a0 and copy it in a1 (0=end of string)
  7071. ;' ' can surround a string
  7072.  
  7073. read_name    movem.l    d0/a1,-(a7)
  7074. .loop        cmp.b    #$20,(a0)+
  7075.         beq.b    .loop
  7076.         subq.l    #1,a0
  7077.         cmp.b    #"'",(a0)
  7078.         bne.b    .colle
  7079.         addq.l    #1,a0
  7080. .loop2        move.b    (a0)+,d0
  7081.         beq.b    .err
  7082.         cmp.b    #"'",d0
  7083.         bne.b    .g1
  7084.         cmp.b    #"'",(a0)
  7085.         bne.b    .end_n
  7086.         addq.l    #1,a0
  7087. .g1        move.b    d0,(a1)+
  7088.         bra.b    .loop2
  7089. .end_n        clr.b    (a1)+
  7090.         movem.l    (a7)+,d0/a1
  7091.         rts
  7092.  
  7093. .colle        move.b    (a0)+,d0
  7094.         beq.b    .err
  7095.         cmp.b    #$20,d0
  7096.         beq.b    .end_n
  7097.         move.b    d0,(a1)+
  7098.         bra.b    .colle
  7099.  
  7100. .err        movem.l    (a7)+,d0/a1
  7101.         clr.b    (a1)
  7102.         rts
  7103.  
  7104. *************************************************************
  7105. ;-> a0=ptr on ascII number
  7106. ;<- returns number in d0
  7107.  
  7108. read_number    movem.l    d1-d3/a1,-(a7)
  7109. .spc        cmp.b    #$20,(a0)+
  7110.         beq.b    .spc
  7111.         subq.l    #1,a0
  7112.         st    ok_numb
  7113.         sf    minus
  7114.         cmp.b    #'-',(a0)
  7115.         bne.b    .no_minus
  7116.         st    minus
  7117.         addq.l    #1,a0
  7118. .no_minus    moveq    #0,d2
  7119.         moveq    #0,d0
  7120.         cmp.b    #'#',(a0)
  7121.         bne.b    no_dec_num
  7122.  
  7123.         addq.l    #1,a0        ;jmp #
  7124.  
  7125. next_dec    move.b    (a0)+,d0
  7126.         cmp.b    #'0',d0
  7127.         blt.w    end_number
  7128.         cmp.b    #'9',d0
  7129.         bgt.w    end_number
  7130.         sub.b    #'0',d0
  7131.  
  7132.         add.l    d2,d2
  7133.         move.l    d2,d3
  7134.         lsl.l    #2,d2
  7135.         add.l    d3,d2        ;mulu    #10,d2
  7136.  
  7137.         add.l    d0,d2
  7138.         sf    ok_numb
  7139.         bra.b    next_dec
  7140.  
  7141. ;-------------- read binary number ------------------
  7142.  
  7143. no_dec_num    cmp.b    #'%',(a0)
  7144.         bne.b    no_bin_num
  7145.         addq.l    #1,a0
  7146.  
  7147.         moveq    #0,d2
  7148. .loop        move.b    (a0)+,d0
  7149.         sub.b    #'0',d0
  7150.         bmi.w    end_number
  7151.         cmp.b    #1,d0
  7152.         bgt.w    end_number
  7153.         add.l    d2,d2
  7154.         or.b    d0,d2
  7155.         sf    ok_numb
  7156.         bra.b    .loop
  7157.  
  7158. no_bin_num    cmp.b    #"'",(a0)
  7159.         bne.b    no_ascII_num
  7160.         addq.l    #1,a0
  7161.         moveq    #0,d2
  7162. .loop        move.b    (a0)+,d0
  7163.         beq.w    end_number
  7164.         cmp.b    #"'",d0
  7165.         bne.b    .no_end_ascII
  7166.         cmp.b    #"'",(a0)
  7167.         bne.b    end_ascII_num
  7168.         addq.l    #1,a0
  7169. .no_end_ascII    lsl.l    #8,d2
  7170.         move.b    d0,d2
  7171.         bra.b    .loop
  7172.  
  7173. end_ascII_num    addq.l    #1,a0
  7174.         sf    ok_numb
  7175.         bra.w    end_number
  7176.  
  7177. ;-------------- read hexa number + label --------------------
  7178.  
  7179. no_ascII_num    move.l    a0,a1
  7180.         tst.b    label    ;test if label enabled
  7181.         bne.b    .no_label
  7182.         bsr    check_label
  7183.         tst.l    d0
  7184.         beq.b    .no_label
  7185.         sf    ok_numb
  7186.         move.l    a4,-(a7)
  7187.         move.l    d0,a4
  7188.         bsr    corr_addr
  7189.         move.l    (a4),d2
  7190.         move.l    (a7)+,a4
  7191.         addq.l    #1,a0
  7192.         bra.b    end_number
  7193.  
  7194. .no_label    move.l    a1,a0
  7195.         cmp.b    #'$',(a0)    ;jmp $ for hex number
  7196.         bne.w    next_dec
  7197.         addq.l    #1,a0        ;jmp $
  7198. .ok_dollar    lea.l    hex_list,a1
  7199. next_hex
  7200.         move.b    (a0)+,d0
  7201.         bsr    upper_case
  7202.         moveq    #$f,d1
  7203. seek_hex    cmp.b    (a1,d1.w),d0
  7204.         dbeq    d1,seek_hex
  7205.         tst.w    d1
  7206.         bmi.b    end_number
  7207.         lsl.l    #4,d2
  7208.         or.w    d1,d2
  7209.         sf    ok_numb
  7210.         bra.b    next_hex
  7211.  
  7212. end_number    subq.l    #1,a0
  7213.         move.l    d2,d0
  7214.         tst.b    minus
  7215.         beq.b    .no_minus
  7216.         neg.l    d0
  7217. .no_minus    tst.b    ok_numb        ;test if error
  7218.         movem.l    (a7)+,d1-d3/a1
  7219.         rts
  7220.  
  7221. check_label    movem.l    d1-d3/a1-a4,-(a7)
  7222.         move.l    a0,d3
  7223.         lea.l    label_list,a1
  7224.  
  7225.         moveq    #0,d2
  7226. .main        tst.b    (a1)
  7227.         beq.b    .end_list
  7228.         move.l    a0,a2
  7229.         move.l    a1,a3
  7230.         moveq    #8-1,d1
  7231. .do_cmp        move.b    (a2)+,d0
  7232.         bsr    upper_case
  7233.         cmp.b    (a3)+,d0
  7234.         bne.b    .no_egal
  7235.         tst.b    (a3)
  7236.         dbeq    d1,.do_cmp
  7237.         move.l    8(a1),d2
  7238.         move.l    a2,a4
  7239. .no_egal    lea.l    8+4(a1),a1
  7240.         bra.b    .main
  7241.  
  7242. .end_list    move.l    a4,a0            ;get end of label
  7243.         move.b    (a0),d0
  7244.         beq.b    .ok_label
  7245.         bsr    upper_case
  7246.         lea.l    .symb_list,a1
  7247. .seek        cmp.b    (a1)+,d0
  7248.         beq.b    .ok_label
  7249.         tst.b    (a1)
  7250.         bne.b    .seek
  7251.         moveq    #0,d2
  7252.         move.l    d3,a0
  7253. .ok_label    move.l    d2,d0
  7254.         movem.l    (a7)+,d1-d3/a1-a4
  7255.         rts
  7256.  
  7257. ;list of symbols which can follow a label.
  7258.  
  7259. .symb_list    dc.b $a,' ','+','-','*','/','&','|',')','.',']',0
  7260.         cnop 0,4
  7261.  
  7262. label_list
  7263.         dc.b "D0",0,0,0,0,0,0
  7264.         dc.l registres
  7265.         dc.b "D1",0,0,0,0,0,0
  7266.         dc.l registres+4
  7267.         dc.b "D2",0,0,0,0,0,0
  7268.         dc.l registres+2*4
  7269.         dc.b "D3",0,0,0,0,0,0
  7270.         dc.l registres+3*4
  7271.         dc.b "D4",0,0,0,0,0,0
  7272.         dc.l registres+4*4
  7273.         dc.b "D5",0,0,0,0,0,0
  7274.         dc.l registres+5*4
  7275.         dc.b "D6",0,0,0,0,0,0
  7276.         dc.l registres+6*4
  7277.         dc.b "D7",0,0,0,0,0,0
  7278.         dc.l registres+7*4
  7279.  
  7280.         dc.b "A0",0,0,0,0,0,0
  7281.         dc.l registres+8*4
  7282.         dc.b "A1",0,0,0,0,0,0
  7283.         dc.l registres+9*4
  7284.         dc.b "A2",0,0,0,0,0,0
  7285.         dc.l registres+10*4
  7286.         dc.b "A3",0,0,0,0,0,0
  7287.         dc.l registres+11*4
  7288.         dc.b "A4",0,0,0,0,0,0
  7289.         dc.l registres+12*4
  7290.         dc.b "A5",0,0,0,0,0,0
  7291.         dc.l registres+13*4
  7292.         dc.b "A6",0,0,0,0,0,0
  7293.         dc.l registres+14*4
  7294.         dc.b "A7",0,0,0,0,0,0
  7295.         dc.l registres+15*4
  7296.  
  7297.         dc.b "PC",0,0,0,0,0,0
  7298.         dc.l pc_reg
  7299.         dc.b "VBR",0,0,0,0,0
  7300.         dc.l vbr_reg
  7301.         dc.b "CACR",0,0,0,0
  7302.         dc.l cacr_reg
  7303.         dc.b "CAAR",0,0,0,0
  7304.         dc.l caar_reg
  7305.         dc.b "PCR",0,0,0,0,0
  7306.         dc.l msp_reg
  7307.         dc.b "BUSR",0,0,0,0
  7308.         dc.l caar_reg
  7309.         dc.b "ISP",0,0,0,0,0
  7310.         dc.l isp_reg
  7311.         dc.b "MSP",0,0,0,0,0
  7312.         dc.l msp_reg
  7313.  
  7314.         dc.b "EXEC",0,0,0,0
  7315.         dc.l $4
  7316.         dc.b "LEV3",0,0,0,0
  7317.         dc.l $6c
  7318.  
  7319.         dc.b 0
  7320.  
  7321.         cnop 0,4
  7322.  
  7323. ************************************************************
  7324.  
  7325. read_fact    cmp.b    #'(',(a0)
  7326.         bne.b    .no_parg
  7327.         addq.l    #1,a0
  7328.         bsr.w    read_expr
  7329.         cmp.b    #')',(a0)+
  7330.         bne.w    eval_error
  7331.         bra.b    end_fact
  7332. .no_parg    cmp.b    #'[',(a0)
  7333.         bne.b    .no_cro
  7334.         addq.l    #1,a0
  7335.         bsr.w    read_expr
  7336.         cmp.b    #']',(a0)+
  7337.         bne.w    eval_error
  7338.         move.l    d0,a4
  7339.         bsr    corr_addr
  7340.         move.l    (a4),d0
  7341.         bra.b    end_fact
  7342. .no_cro        bsr    read_number
  7343.         bne.w    eval_error
  7344.  
  7345. end_fact    cmp.b    #'.',(a0)
  7346.         bne.b    .no_size
  7347.         addq.l    #1,a0            ;jmp .
  7348.         move.l    d1,-(a7)
  7349.         move.b    (a0)+,d1
  7350.         bsr    upper_case1
  7351.         cmp.b    #'B',d1
  7352.         bne.b    .no_b
  7353.         ext.w    d0
  7354.         ext.l    d0
  7355.         clr.w    eval_size
  7356.         bra.b    .end_size
  7357. .no_b        cmp.b    #'W',d1
  7358.         bne.b    .no_w
  7359.         ext.l    d0
  7360.         move.w    #1,eval_size
  7361.         bra.b    .end_size
  7362. .no_w        cmp.b    #'L',d1
  7363.         bne.w    eval_error
  7364.         move.w    #3,eval_size
  7365. .end_size    move.l    (a7)+,d1
  7366. .no_size    rts
  7367.  
  7368.  
  7369. read_terme    move.l    d1,-(a7)
  7370.         bsr.w    read_fact
  7371.         move.l    d0,d1
  7372. .loop        cmp.b    #'*',(a0)
  7373.         bne.b    .no_fois
  7374.         addq.l    #1,a0
  7375.         bsr.w    read_fact
  7376.         bsr.w    muls32
  7377.         bra.b    .loop
  7378. .no_fois    cmp.b    #'/',(a0)
  7379.         bne.b    .no_div
  7380.         addq.l    #1,a0
  7381.         bsr.w    read_fact
  7382.         bsr.w    divs32
  7383.         bra.b    .loop
  7384. .no_div        move.l    d1,d0
  7385.         move.l    (a7)+,d1
  7386.         rts
  7387.  
  7388. read_expr    move.l    d1,-(a7)
  7389.         cmp.b    #'+',(a0)
  7390.         bne.b    .no_p
  7391.         addq.l    #1,a0
  7392. .no_p        cmp.b    #'-',(a0)
  7393.         bne.b    .no_m
  7394.         addq.l    #1,a0
  7395.         bsr.b    read_terme
  7396.         neg.l    d0
  7397.         bra.b    .ok_m
  7398. .no_m        bsr.b    read_terme
  7399. .ok_m        move.l    d0,d1
  7400. .loop        cmp.b    #'+',(a0)
  7401.         bne.b    .no_plus
  7402.         addq.l    #1,a0
  7403.         bsr.b    read_terme
  7404.         add.l    d0,d1
  7405.         bra.b    .loop
  7406. .no_plus    cmp.b    #'-',(a0)
  7407.         bne.b    .no_moins
  7408.         addq.l    #1,a0
  7409.         bsr.b    read_terme
  7410.         sub.l    d0,d1
  7411.         bra.b    .loop
  7412. .no_moins    move.l    d1,d0
  7413.         move.l    (a7)+,d1
  7414.         rts
  7415.  
  7416. ;-> a0 =ptr on expr
  7417. ;<- d0 value
  7418. ;<- flag: zero=ok, negative=error, positive=no number
  7419.  
  7420. evaluate:    move.l    a7,exit_stack
  7421. .loop        cmp.b    #$20,(a0)+
  7422.         beq.b    .loop
  7423.         subq.l    #1,a0
  7424.         tst.b    (a0)
  7425.         beq.b    .no_eval
  7426.         bsr    read_expr
  7427.         tst.b    ok    ;zero = ok
  7428.         rts
  7429. .no_eval    tst.b    ok2
  7430.         rts
  7431. eval_error    move.l    exit_stack,a7
  7432.         moveq    #-1,d0        ;neg val = error
  7433.         rts
  7434.  
  7435. ok        dc.b 0
  7436. ok2        dc.b 1            ;positive val = no number
  7437.  
  7438. ;d0.l,d1.l
  7439. ;d1.l=d0.l*d1.l
  7440. muls32        movem.l    d0/d2/a0,-(a7)
  7441.         lea.l    muls_data,a0
  7442.         movem.l    d0-d1,(a0)
  7443.         swap    d0
  7444.         mulu    d0,d1
  7445.         move.w    d1,d2
  7446.         movem.l    (a0),d0-d1
  7447.         swap    d1
  7448.         mulu    d0,d1
  7449.         add.w    d1,d2
  7450.         swap    d2
  7451.         clr.w    d2
  7452.         movem.l    (a0),d0-d1
  7453.         mulu    d0,d1
  7454.         add.l    d2,d1
  7455.         movem.l    (a7)+,d0/d2/a0
  7456.         rts
  7457.  
  7458.  
  7459. ;d0.l,d1.l
  7460. ;d1.l=d1.l/d0.l
  7461. divs32        movem.l    d0/d2-d4/a0,-(a7)
  7462.         exg    d0,d1
  7463.         sf    d4
  7464.         tst.l    d0
  7465.         bpl.b    .n1
  7466.         neg.l    d0
  7467.         not.b    d4
  7468. .n1        tst.l    d1
  7469.         bpl.b    .n2
  7470.         neg.l    d1
  7471.         not.b    d4
  7472. .n2        move.l    #$ffff,d3
  7473.         lea.l    divs_data,a0
  7474.         movem.l    d0-d1,(a0)
  7475.         moveq    #0,d2
  7476.         cmp.l    #$10000,d1
  7477.         bge.b    .div2
  7478.  
  7479.         tst.w    d1
  7480.         beq.w    eval_error
  7481.  
  7482.         swap    d0
  7483.         and.l    d3,d0
  7484.         divu    d1,d0
  7485.         move.w    d0,d2
  7486.         swap    d2
  7487.         clr.w    d2
  7488.         move.w    2(a0),d0
  7489.         divu    d1,d0
  7490.         and.l    d3,d0
  7491.         add.l    d0,d2
  7492.         bra.b    .ok1
  7493.  
  7494. .div2        lsr.l    #1,d0
  7495.         lsr.l    #1,d1
  7496.         cmp.l    #$10000,d1
  7497.         bge.b    .div2
  7498.         tst.w    d1
  7499.         beq.w    eval_error
  7500.         divu    d1,d0
  7501.         move.w    d0,d2
  7502.         and.l    d3,d2
  7503.  
  7504. .ok1        tst.b    d4
  7505.         beq.b    .n3
  7506.         neg.l    d2
  7507. .n3        move.l    d2,d1
  7508.         movem.l    (a7)+,d0/d2-d4/a0
  7509.         rts
  7510.  
  7511. ************************************************************
  7512. ;-> a0=ptr on ascII registre
  7513. ;<- returns no of registre in d0 and end of ascII reg in a0
  7514.  
  7515. read_reg    movem.l    d1-d3/a1-a4,-(a7)
  7516.         move.l    a0,d3
  7517.         lea.l    reg_table,a1
  7518.  
  7519.         moveq    #-1,d2
  7520. .main        tst.b    (a1)
  7521.         beq.b    .end_list
  7522.         move.l    a0,a2
  7523.         move.l    a1,a3
  7524.         moveq    #4-1,d1
  7525. .do_cmp        move.b    (a2)+,d0
  7526.         bsr    upper_case
  7527.         cmp.b    (a3)+,d0
  7528.         bne.b    .no_egal
  7529.         tst.b    (a3)
  7530.         dbeq    d1,.do_cmp
  7531.         move.w    4(a1),d2
  7532.         move.l    a2,a4
  7533. .no_egal    lea.l    4+2(a1),a1
  7534.         bra.b    .main
  7535.  
  7536. .end_list    move.l    a4,a0            ;get end of register
  7537.         move.w    d2,d0
  7538.         movem.l    (a7)+,d1-d3/a1-a4
  7539.         rts
  7540.  
  7541. reg_table
  7542.         dc.b "D0",0,0
  7543.         dc.w 0
  7544.         dc.b "D1",0,0
  7545.         dc.w 1
  7546.         dc.b "D2",0,0
  7547.         dc.w 2
  7548.         dc.b "D3",0,0
  7549.         dc.w 3
  7550.         dc.b "D4",0,0
  7551.         dc.w 4
  7552.         dc.b "D5",0,0
  7553.         dc.w 5
  7554.         dc.b "D6",0,0
  7555.         dc.w 6
  7556.         dc.b "D7",0,0
  7557.         dc.w 7
  7558.         dc.b "A0",0,0
  7559.         dc.w 8
  7560.         dc.b "A1",0,0
  7561.         dc.w 9
  7562.         dc.b "A2",0,0
  7563.         dc.w 10
  7564.         dc.b "A3",0,0
  7565.         dc.w 11
  7566.         dc.b "A4",0,0
  7567.         dc.w 12
  7568.         dc.b "A5",0,0
  7569.         dc.w 13
  7570.         dc.b "A6",0,0
  7571.         dc.w 14
  7572.         dc.b "A7",0,0
  7573.         dc.w 15
  7574.         dc.b "PC",0,0
  7575.         dc.w 16
  7576.         dc.b "SR",0,0
  7577.         dc.w 17
  7578.         dc.b "VBR",0
  7579.         dc.w 18
  7580.         dc.b "USP",0
  7581.         dc.w 19
  7582.         dc.b "SSP",0
  7583.         dc.w 20
  7584.         dc.b "CACR"
  7585.         dc.w 21
  7586.         dc.b "PCR",0
  7587.         dc.w 22
  7588.         dc.b "BUSR"
  7589.         dc.w 23
  7590.         dc.w 0
  7591.  
  7592.  
  7593. ************************************************************
  7594. ;-------------- Run-length packing -------------------------
  7595.  
  7596. ;-> a0=ptr on source mem to pack
  7597. ;-> a1=destination mem
  7598. ;-> d0.w=size to pack
  7599. ;<- d0.w=packed size
  7600.  
  7601. pack        movem.l    d1-d6/a0-a4,-(a7)
  7602.         move.w    #$100,$dff096        ;disable bitplan DMA
  7603.  
  7604.         move.w    #0,$dff106
  7605.         move.l    a1,a4
  7606.         lea.l    8(a4),a2
  7607.         move.l    d0,4(a4)
  7608.  
  7609.         move.l    a0,a3
  7610.         move.l    d0,d3            ;d3=original size
  7611.  
  7612.         move.l    d0,d5            ;d5=nb of bytes still to pack
  7613.  
  7614. .loop        move.l    d5,d6
  7615.         cmp.l    #128,d6
  7616.         ble.b    .min
  7617.         moveq    #127,d6
  7618.         addq.l    #1,d6            ;d6=128
  7619. .min
  7620.         move.l    d6,d0
  7621.         subq.l    #1,d0            ;d6=1 ?
  7622.         bne.b    .no1
  7623.         move.b    (a0)+,(a2)+
  7624.         sf    (a2)+
  7625.         bra.b    .end
  7626. .no1
  7627.         move.b    (a0)+,d0
  7628.         move.b    d0,$dff180
  7629.         move.b    (a0)+,d1
  7630.         cmp.b    d0,d1
  7631.         bne.b    .diff
  7632.  
  7633.         moveq    #1,d4
  7634.         subq.l    #1,d6
  7635.  
  7636. .cntsame    addq.l    #1,d4
  7637.         subq.l    #1,d6
  7638.         beq.b    .out2
  7639.         cmp.b    (a0)+,d0
  7640.         beq.b    .cntsame
  7641.         subq.l    #1,a0
  7642. .out2
  7643.         sub.l    d4,d5
  7644.         neg.w    d4
  7645.         move.b    d0,(a2)+
  7646.         move.b    d4,(a2)+
  7647.         tst.l    d5
  7648.         beq.b    .end
  7649.         bra.b    .loop
  7650.  
  7651. ;---------------------------------
  7652. .diff        lea.l    -2(a0),a1
  7653.         moveq    #0,d4
  7654. .cntdiff    move.b    d1,d0
  7655.         addq.l    #1,d4
  7656.         subq.l    #1,d6
  7657.         beq.b    .out
  7658.         move.b    (a0)+,d1
  7659.         cmp.b    d0,d1
  7660.         bne.b    .cntdiff
  7661.         subq.l    #1,a0
  7662.  
  7663. .out        subq.l    #1,a0
  7664.         sub.l    d4,d5
  7665.         subq.l    #1,d4
  7666.         move.w    d4,d0
  7667. .copy        move.b    (a1)+,(a2)+
  7668.         dbf    d4,.copy
  7669.         move.b    d0,(a2)+
  7670.         tst.l    d5            ;end of block ?
  7671.         bne.b    .loop
  7672.  
  7673. .end        move.l    a2,d0
  7674.         lea.l    8(a4),a1
  7675.         sub.l    a1,d0            ;d0=packed size
  7676.         move.l    d0,(a4)            ;first long=packed size
  7677.         cmp.l    d0,d3
  7678.         bgt.b    .pack
  7679.         lea.l    8(a4),a1
  7680.         move.l    d3,d0
  7681.         neg.l    d0
  7682.         move.l    d0,(a4)
  7683.         move.l    d3,d0
  7684.         move.b    d3,d1
  7685.         lsr.l    #2,d3
  7686. .copyl        move.l    (a3)+,(a1)+        ;copy unpacked area
  7687.         subq.l    #1,d3
  7688.         bne.b    .copyl
  7689.         and.w    #3,d1
  7690.         bra.b    .godbf
  7691. .copyb        move.b    (a3)+,(a1)+
  7692. .godbf        dbf    d1,.copyb
  7693. .pack
  7694.         addq.l    #8,d0            ;for first long=size
  7695.  
  7696.         move.w    #0,$dff106
  7697.         move.w    #0,$dff180
  7698.         move.w    #$8100,$dff096        ;enable bitplan DMA
  7699.  
  7700.         movem.l    (a7)+,d1-d6/a0-a4
  7701.         rts
  7702.  
  7703. ;----------------------------------------------------------
  7704.  
  7705. ;-> a0=ptr on packed mem
  7706. ;-> a1=ptr on dest mem
  7707.  
  7708. depack        movem.l    d0-d1/a0-a2,-(a7)
  7709.         move.w    #0,$dff106
  7710.         move.w    #$100,$dff096        ;disable bitplan DMA
  7711.  
  7712.         tst.l    (a0)
  7713.         bmi.b    .nopack
  7714.         movem.l    (a0)+,d0-d1
  7715.         move.l    a0,a2
  7716.         add.l    d0,a0
  7717.         add.l    d1,a1
  7718.  
  7719. .loop        cmp.l    a2,a0
  7720.         beq.b    .end
  7721.         moveq    #0,d0
  7722.         move.b    -(a0),d0
  7723.         bmi.b    .neg
  7724. .copy        move.b    -(a0),-(a1)
  7725.         dbf    d0,.copy
  7726.         move.b    (a1),$dff180
  7727.         bra.b    .loop
  7728. .neg        ext.w    d0
  7729.         not.w    d0
  7730.         move.b    -(a0),d1
  7731.         move.b    d1,$dff180
  7732. .fill        move.b    d1,-(a1)
  7733.         dbf    d0,.fill
  7734.         bra.b    .loop
  7735.  
  7736. .nopack        addq.l    #8,a0
  7737.         move.l    4(a0),d0
  7738.         move.b    d0,d1
  7739.         lsr.l    #2,d0
  7740. .copyl        move.l    (a0)+,(a1)+
  7741.         subq.l    #1,d0
  7742.         bne.b    .copyl
  7743.         and.w    #3,d1
  7744.         bra.b    .godbf
  7745. .copyb        move.b    (a0)+,(a1)+
  7746. .godbf        dbf    d1,.copyb
  7747.  
  7748. .end
  7749.         move.w    #0,$dff106
  7750.         move.w    #0,$dff180
  7751.         move.w    #$8100,$dff096        ;enable bitplan DMA
  7752.  
  7753.         movem.l    (a7)+,d0-d1/a0-a2
  7754.         rts
  7755.  
  7756. ************************************************************
  7757.  
  7758. ;a0=ptr on text
  7759.  
  7760. print_curs    bsr    clear_cursor    ;special print which clears cursor
  7761.         clr.w    cursor_x    ;and set it to x=0
  7762.         bsr.b    print
  7763.         bsr    set_cursor
  7764.         rts
  7765.  
  7766.  
  7767. print:        movem.l    d0-d2/a0-a4,-(a7)
  7768.         move.l    output_ptr,d0
  7769.         beq.b    .noout
  7770.         move.l    a0,a1
  7771.         move.l    d0,a2
  7772. .copy        move.b    (a1)+,(a2)+
  7773.         bne.b    .copy
  7774.         subq.l    #1,a2
  7775.         move.l    a2,output_ptr
  7776. ;        move.l    a2,watch2
  7777.  
  7778. .noout        move.w    window_bot,d2
  7779.         lea.l    cursor_x,a3
  7780.         move.w    2(a3),d0
  7781.         cmp.w    window_top,d0
  7782.         bge.b    .ok1
  7783.         move.w    window_top,d0
  7784. .ok1        cmp.w    window_bot,d0
  7785.         blt.b    .ok2
  7786.         move.w    window_bot,d0
  7787. .ok2        move.w    d0,2(a3)
  7788.  
  7789.         move.l    ascII_ptr,a2
  7790.         lea.l    print_cnt,a4
  7791.         clr.w    (a4)
  7792.  
  7793. print_next
  7794. go_print    tst.b    break
  7795.         bne.w    end_print
  7796.         move.w    2(a3),d0
  7797.         mulu    #80,d0
  7798.         lea.l    (a2,d0.l),a1
  7799.         add.w    (a3),a1
  7800.  
  7801.         move.b    (a0)+,d0
  7802.         beq.b    end_printl
  7803.         cmp.b    #$0a,d0
  7804.         beq.b    end_printl
  7805.         cmp.b    #9,d0
  7806.         bne.b    .no_tab
  7807.         move.w    (a3),d0
  7808.         and.w    #$fff8,d0
  7809.         addq.w    #8,d0
  7810.         move.w    d0,(a3)
  7811.         bra.b    go_print
  7812. .no_tab        cmp.b    #$0d,d0
  7813.         bne.b    .no_13
  7814.         clr.w    (a3)
  7815.         bra.b    go_print
  7816.  
  7817. .no_13        move.b    d0,(a1)
  7818.  
  7819.         addq.w    #1,(a3)
  7820.         cmp.w    #80,(a3)
  7821.         blt.b    .ok
  7822.         clr.w    (a3)
  7823.         move.w    2(a3),d0
  7824.         bsr    print_line
  7825.         addq.w    #1,(a4)
  7826.         cmp.w    (a4),d2
  7827.         bgt.b    .okp
  7828.         bsr.b    print_wait
  7829. .okp        cmp.w    2(a3),d2
  7830.         bgt.b    .ok_cr_prt
  7831.         subq.w    #1,2(a3)
  7832.         bsr    scroll_up
  7833. .ok_cr_prt    addq.w    #1,2(a3)
  7834. .ok
  7835.         bra.b    go_print
  7836.  
  7837. end_printl    tst.b    d0
  7838.         beq.b    end_print
  7839. ;-------------- print CR -------------------
  7840.         move.w    2(a3),d0
  7841.         bsr    print_line
  7842.         addq.w    #1,(a4)
  7843.         cmp.w    (a4),d2
  7844.         bgt.b    .okp
  7845.         bsr.b    print_wait
  7846. .okp        clr.w    (a3)
  7847.         cmp.w    2(a3),d2
  7848.         bgt.b    .ok_cr_prt
  7849.         subq.w    #1,2(a3)
  7850.         bsr    scroll_up
  7851. .ok_cr_prt    addq.w    #1,2(a3)
  7852.         tst.b    (a0)
  7853.         beq.b    end_print_out
  7854.         bra.w    print_next
  7855. ;-------------------------------------------
  7856. end_print    move.w    2(a3),d0
  7857.         bsr    print_line
  7858. end_print_out
  7859.         movem.l    (a7)+,d0-d2/a0-a4
  7860.         rts
  7861.  
  7862. print_wait    tst.b    no_print
  7863.         bne.b    .nowait
  7864.         clr.w    (a4)
  7865.         st    new_key
  7866. .wait        move.w    #15,time_cursor
  7867.         tst.b    new_key
  7868.         bne.b    .wait
  7869. .nowait        rts
  7870.  
  7871. ************************************************************
  7872.  
  7873. no_sc_clr    dc.b 0
  7874.         even
  7875.  
  7876. scroll_up    move.l    d2,-(a7)
  7877.         moveq    #1,d2
  7878.         bsr.b    scroll_up2
  7879.         move.l    (a7)+,d2
  7880.         rts
  7881.  
  7882. ;-> d2 = nb of lines
  7883.  
  7884. scroll_up2    movem.l    d0-d1/a0-a1,-(a7)
  7885.         move.l    ascII_ptr,a0
  7886.         move.w    window_top,d0
  7887.         mulu    #80,d0
  7888.         add.l    d0,a0
  7889.         move.w    d2,d0
  7890.         mulu    #80,d0
  7891.         lea.l    (a0,d0.l),a1
  7892.         move.w    window_bot,d0
  7893.         sub.w    window_top,d0
  7894.         sub.w    d2,d0
  7895.         addq.w    #1,d0
  7896.         bra.b    .go_dbf
  7897. .ascII_up    move.l    (a1)+,(a0)+
  7898.         move.l    (a1)+,(a0)+
  7899.         move.l    (a1)+,(a0)+
  7900.         move.l    (a1)+,(a0)+
  7901.         move.l    (a1)+,(a0)+
  7902.         move.l    (a1)+,(a0)+
  7903.         move.l    (a1)+,(a0)+
  7904.         move.l    (a1)+,(a0)+
  7905.         move.l    (a1)+,(a0)+
  7906.         move.l    (a1)+,(a0)+
  7907.         move.l    (a1)+,(a0)+
  7908.         move.l    (a1)+,(a0)+
  7909.         move.l    (a1)+,(a0)+
  7910.         move.l    (a1)+,(a0)+
  7911.         move.l    (a1)+,(a0)+
  7912.         move.l    (a1)+,(a0)+
  7913.         move.l    (a1)+,(a0)+
  7914.         move.l    (a1)+,(a0)+
  7915.         move.l    (a1)+,(a0)+
  7916.         move.l    (a1)+,(a0)+
  7917. .go_dbf        dbf    d0,.ascII_up
  7918.         move.l    #'    ',d0
  7919.         moveq    #5,d1
  7920.         mulu    d2,d1
  7921.         subq.w    #1,d1
  7922. .clear_up    move.l    d0,(a0)+
  7923.         move.l    d0,(a0)+
  7924.         move.l    d0,(a0)+
  7925.         move.l    d0,(a0)+
  7926.         dbf    d1,.clear_up
  7927.  
  7928.         tst.b    no_print
  7929.         bne.w    .noscroll
  7930.  
  7931.         move.l    pic_ptr,a0
  7932.         move.w    window_top,d0
  7933.         mulu    #80*h,d0
  7934.         add.l    d0,a0
  7935.         move.w    d2,d0
  7936.         mulu    #80*h,d0
  7937.         lea.l    (a0,d0.l),a1
  7938.         move.w    window_bot,d0
  7939.         sub.w    window_top,d0
  7940.         sub.w    d2,d0
  7941.         addq.w    #1,d0
  7942.         mulu    #h,d0
  7943.         bra.b    .go_dbf2
  7944. .pixel_up    move.l    (a1)+,(a0)+
  7945.         move.l    (a1)+,(a0)+
  7946.         move.l    (a1)+,(a0)+
  7947.         move.l    (a1)+,(a0)+
  7948.         move.l    (a1)+,(a0)+
  7949.         move.l    (a1)+,(a0)+
  7950.         move.l    (a1)+,(a0)+
  7951.         move.l    (a1)+,(a0)+
  7952.         move.l    (a1)+,(a0)+
  7953.         move.l    (a1)+,(a0)+
  7954.         move.l    (a1)+,(a0)+
  7955.         move.l    (a1)+,(a0)+
  7956.         move.l    (a1)+,(a0)+
  7957.         move.l    (a1)+,(a0)+
  7958.         move.l    (a1)+,(a0)+
  7959.         move.l    (a1)+,(a0)+
  7960.         move.l    (a1)+,(a0)+
  7961.         move.l    (a1)+,(a0)+
  7962.         move.l    (a1)+,(a0)+
  7963.         move.l    (a1)+,(a0)+
  7964. .go_dbf2    dbf    d0,.pixel_up
  7965.  
  7966.         moveq    #0,d0
  7967.         tst.b    no_sc_clr
  7968.         beq.b    .goclr
  7969.         move.w    d2,d1
  7970.         subq.w    #1,d1
  7971.         mulu    #80*h,d1
  7972.         add.l    d1,a0
  7973.         moveq    #5*h-1,d1
  7974.         bra.b    .clear_pix_up
  7975. .goclr        move.w    d2,d1
  7976.         mulu    #5*h,d1
  7977.         subq.w    #1,d1
  7978. .clear_pix_up    move.l    d0,(a0)+
  7979.         move.l    d0,(a0)+
  7980.         move.l    d0,(a0)+
  7981.         move.l    d0,(a0)+
  7982.         dbf    d1,.clear_pix_up
  7983.  
  7984. .noscroll    movem.l    (a7)+,d0-d1/a0-a1
  7985.         rts
  7986.  
  7987. ;-------------------------------------------
  7988.  
  7989. scroll_down    move.l    d2,-(a7)
  7990.         moveq    #1,d2
  7991.         bsr.b    scroll_down2
  7992.         move.l    (a7)+,d2
  7993.         rts
  7994.  
  7995. ;-> d2 = nb of lines
  7996.  
  7997. scroll_down2    movem.l    d0-d1/a0-a1,-(a7)
  7998.  
  7999.         move.l    ascII_ptr,a0
  8000.         move.w    window_bot,d0
  8001.         mulu    #80,d0
  8002.         add.l    d0,a0
  8003.         move.l    a0,a1
  8004.         move.w    d2,d0
  8005.         subq.w    #1,d0
  8006.         mulu    #80,d0
  8007.         sub.l    d0,a1
  8008.         lea.l    80(a0),a0
  8009.         move.w    window_bot,d0
  8010.         sub.w    window_top,d0
  8011.         sub.w    d2,d0
  8012.         addq.w    #1,d0
  8013.         bra.b    .go_dbf
  8014. .ascII_down    move.l    -(a1),-(a0)
  8015.         move.l    -(a1),-(a0)
  8016.         move.l    -(a1),-(a0)
  8017.         move.l    -(a1),-(a0)
  8018.         move.l    -(a1),-(a0)
  8019.         move.l    -(a1),-(a0)
  8020.         move.l    -(a1),-(a0)
  8021.         move.l    -(a1),-(a0)
  8022.         move.l    -(a1),-(a0)
  8023.         move.l    -(a1),-(a0)
  8024.         move.l    -(a1),-(a0)
  8025.         move.l    -(a1),-(a0)
  8026.         move.l    -(a1),-(a0)
  8027.         move.l    -(a1),-(a0)
  8028.         move.l    -(a1),-(a0)
  8029.         move.l    -(a1),-(a0)
  8030.         move.l    -(a1),-(a0)
  8031.         move.l    -(a1),-(a0)
  8032.         move.l    -(a1),-(a0)
  8033.         move.l    -(a1),-(a0)
  8034. .go_dbf        dbf    d0,.ascII_down
  8035.         move.l    #'    ',d0
  8036.         move.w    d2,d1
  8037.         mulu    #5,d1
  8038.         subq.w    #1,d1
  8039. .clear_down    move.l    d0,-(a0)
  8040.         move.l    d0,-(a0)
  8041.         move.l    d0,-(a0)
  8042.         move.l    d0,-(a0)
  8043.         dbf    d1,.clear_down
  8044.  
  8045.         tst.b    no_print
  8046.         bne.w    .noscroll
  8047.  
  8048.         move.l    pic_ptr,a0
  8049.         move.w    window_bot,d0
  8050.         mulu    #80*h,d0
  8051.         add.l    d0,a0
  8052.         move.l    a0,a1
  8053.         move.w    d2,d0
  8054.         subq.w    #1,d0
  8055.         mulu    #80*h,d0
  8056.         sub.l    d0,a1
  8057.         lea.l    80*h(a0),a0
  8058.  
  8059.         move.w    window_bot,d0
  8060.         sub.w    window_top,d0
  8061.         sub.w    d2,d0
  8062.         addq.w    #1,d0
  8063.         mulu    #h,d0
  8064.         bra.b    .go_dbf2
  8065. .pixel_down    move.l    -(a1),-(a0)
  8066.         move.l    -(a1),-(a0)
  8067.         move.l    -(a1),-(a0)
  8068.         move.l    -(a1),-(a0)
  8069.         move.l    -(a1),-(a0)
  8070.         move.l    -(a1),-(a0)
  8071.         move.l    -(a1),-(a0)
  8072.         move.l    -(a1),-(a0)
  8073.         move.l    -(a1),-(a0)
  8074.         move.l    -(a1),-(a0)
  8075.         move.l    -(a1),-(a0)
  8076.         move.l    -(a1),-(a0)
  8077.         move.l    -(a1),-(a0)
  8078.         move.l    -(a1),-(a0)
  8079.         move.l    -(a1),-(a0)
  8080.         move.l    -(a1),-(a0)
  8081.         move.l    -(a1),-(a0)
  8082.         move.l    -(a1),-(a0)
  8083.         move.l    -(a1),-(a0)
  8084.         move.l    -(a1),-(a0)
  8085. .go_dbf2    dbf    d0,.pixel_down
  8086.  
  8087.         moveq    #0,d0
  8088.         tst.b    no_sc_clr
  8089.         beq.b    .goclr
  8090.         move.w    d2,d1
  8091.         subq.w    #1,d1
  8092.         mulu    #80*h,d1
  8093.         sub.l    d1,a0
  8094.         moveq    #5*h-1,d1
  8095.         bra.b    .clear_pix_down
  8096. .goclr        move.w    d2,d1
  8097.         mulu    #5*h,d1
  8098.         subq.w    #1,d1
  8099. .clear_pix_down    move.l    d0,-(a0)
  8100.         move.l    d0,-(a0)
  8101.         move.l    d0,-(a0)
  8102.         move.l    d0,-(a0)
  8103.         dbf    d1,.clear_pix_down
  8104.  
  8105. .noscroll    movem.l    (a7)+,d0-d1/a0-a1
  8106.         rts
  8107.  
  8108. ************************************************************
  8109.  
  8110. ;d0=no of line
  8111.  
  8112. print_line    movem.l    d0-d4/a0-a4,-(a7)
  8113.         tst.b    no_print
  8114.         bne.w    .no_print
  8115.  
  8116.         move.l    ascII_ptr,a0
  8117.         mulu    #80,d0
  8118.         add.l    d0,a0
  8119.         move.l    pic_ptr,a1
  8120.         mulu    #h,d0
  8121.         add.l    d0,a1
  8122.  
  8123.         lea.l    topaz2,a3
  8124.         lea.l    ascII_conv,a4
  8125.         moveq    #80-1,d4
  8126.         moveq    #0,d2
  8127.         moveq    #0,d0
  8128.  
  8129. .do_line_prt    move.b    (a0)+,d2
  8130.  
  8131.         move.b    (a4,d2.w),d0
  8132.         lea.l    (a3,d0.w),a2
  8133.  
  8134.         move.b    110(a2),80(a1)
  8135.         move.b    220(a2),160(a1)
  8136.         move.b    330(a2),240(a1)
  8137.         move.b    440(a2),320(a1)
  8138.         move.b    550(a2),400(a1)
  8139.         move.b    660(a2),480(a1)
  8140.         move.b    770(a2),560(a1)
  8141.         move.b    880(a2),640(a1)
  8142.         move.b    (a2),(a1)+
  8143.  
  8144.         dbf    d4,.do_line_prt
  8145.  
  8146. .stop_print    move.w    #15,time_cursor
  8147.         btst    #10-8,$dff016
  8148.         beq.b    .stop_print
  8149.  
  8150. .no_print    movem.l    (a7)+,d0-d4/a0-a4
  8151.         rts
  8152.  
  8153. ;---------------------------------------------------
  8154.  
  8155. ;d0=x pos
  8156. ;d1=y pos
  8157. ;d2=ascII char
  8158.  
  8159. print_char    movem.l    d0-d2/a1-a2,-(a7)
  8160.         move.l    ascII_ptr,a1
  8161.         add.w    d0,a1
  8162.         lsl.w    #4,d1
  8163.         move.w    d1,a2
  8164.         add.w    d1,d1
  8165.         add.w    d1,d1
  8166.         add.w    a2,d1            ;d1*80
  8167.         move.b    d2,(a1,d1.w)
  8168.  
  8169.         and.w    #$ff,d2
  8170.  
  8171.         lea.l    ascII_conv,a2
  8172.         move.b    (a2,d2.w),d2
  8173.         lea.l    topaz2,a2
  8174.         lea.l    (a2,d2.w),a2
  8175.  
  8176.         move.l    pic_ptr,a1
  8177.         add.w    d0,a1
  8178.         mulu    #h,d1
  8179.         add.l    d1,a1
  8180.         move.b    (a2),(a1)
  8181.         move.b    110(a2),80(a1)
  8182.         move.b    220(a2),160(a1)
  8183.         move.b    330(a2),240(a1)
  8184.         move.b    440(a2),320(a1)
  8185.         move.b    550(a2),400(a1)
  8186.         move.b    660(a2),480(a1)
  8187.         move.b    770(a2),560(a1)
  8188.         move.b    880(a2),640(a1)
  8189.         movem.l    (a7)+,d0-d2/a1-a2
  8190.         rts
  8191.  
  8192.  
  8193. ;d0=x pos
  8194. ;d1=y pos
  8195. ;d2=ascII char
  8196.  
  8197. ;print on all screens
  8198.  
  8199. print_char2    movem.l    d0-d2/a1-a3,-(a7)
  8200.         lsl.w    #4,d1
  8201.         move.w    d1,a2
  8202.         add.w    d1,d1
  8203.         add.w    d1,d1
  8204.         add.w    a2,d1            ;d1*80
  8205.         add.w    d0,d1
  8206.         lea.l    ascII_ptr+4,a1
  8207. .loop        tst.l    (a1)
  8208.         beq.b    .end_ascII
  8209.         move.l    (a1)+,a3
  8210.         move.b    d2,(a3,d1.w)
  8211.         bra.b    .loop
  8212.  
  8213. .end_ascII    and.w    #$ff,d2
  8214.  
  8215.         lea.l    ascII_conv,a2
  8216.         move.b    (a2,d2.w),d2
  8217.         lea.l    topaz2,a2
  8218.         lea.l    (a2,d2.w),a2
  8219.  
  8220.         sub.w    d0,d1
  8221.  
  8222.         move.l    pic_ptr,a1
  8223.         add.w    d0,a1
  8224.         mulu    #h,d1
  8225.         add.l    d1,a1
  8226.         move.b    (a2),(a1)
  8227.         move.b    110(a2),80(a1)
  8228.         move.b    220(a2),160(a1)
  8229.         move.b    330(a2),240(a1)
  8230.         move.b    440(a2),320(a1)
  8231.         move.b    550(a2),400(a1)
  8232.         move.b    660(a2),480(a1)
  8233.         move.b    770(a2),560(a1)
  8234.         move.b    880(a2),640(a1)
  8235.         movem.l    (a7)+,d0-d2/a1-a3
  8236.         rts
  8237.  
  8238. do_cursor:    bsr    clear_snap
  8239.         tst.b    no_curs
  8240.         bne.w    .no_cur
  8241.  
  8242.         movem.l    d0-a6,-(a7)
  8243.         lea.l    $dff000,a6
  8244.         bsr    init_mouse
  8245.         move.w    x_spr,d0
  8246.         bpl.b    .ok1
  8247.         clr.w    d0
  8248. .ok1        cmp.w    #640,d0
  8249.         blt.b    .ok2
  8250.         move.w    #639,d0
  8251. .ok2        move.w    d0,x_spr
  8252.         lsr    #3,d0
  8253.         move.w    d0,snap_x
  8254.         move.w    y_spr,d0
  8255.         bpl.b    .ok3
  8256.         clr.w    d0
  8257. .ok3        move.w    screen_height,d1
  8258.         mulu    #9,d1
  8259.         cmp.w    d1,d0
  8260.         blt.b    .ok4
  8261.         move.w    d1,d0
  8262.         subq.w    #1,d0
  8263. .ok4        move.w    d0,y_spr
  8264.         ext.l    d0
  8265.         divu    #9,d0
  8266.         move.w    d0,snap_y
  8267.         bsr    set_snap
  8268.  
  8269.         tst.b    nosnap
  8270.         bne.w    .nos
  8271.         tst.b    left
  8272.         beq.w    .noleft
  8273.         move.l    ascII_ptr,a0
  8274.         move.w    snap_y,d0
  8275.         mulu    #80,d0
  8276.         add.l    d0,a0
  8277.         move.w    snap_x,d0
  8278.         cmp.b    #$20,(a0,d0.w)
  8279.         beq.b    .noleft
  8280. .redeb        tst.w    d0
  8281.         beq.b    .debs
  8282.         cmp.b    #$20,-1(a0,d0.w)
  8283.         beq.b    .debs
  8284.         cmp.b    #';',-1(a0,d0.w)
  8285.         beq.b    .debs
  8286.         cmp.b    #'=',-1(a0,d0.w)
  8287.         beq.b    .debs
  8288.         cmp.b    #'(',-1(a0,d0.w)
  8289.         beq.b    .debs
  8290.         cmp.b    #',',-1(a0,d0.w)
  8291.         beq.b    .debs
  8292.         subq.w    #1,d0
  8293.         bra.b    .redeb
  8294. .debs
  8295.         lea.l    snap_buf,a1
  8296. .cops        move.b    (a0,d0.w),(a1)+
  8297.         addq.w    #1,d0
  8298.         cmp.w    #80,d0
  8299.         beq.b    .ends
  8300.         cmp.b    #',',(a0,d0.w)
  8301.         beq.b    .ends
  8302.         cmp.b    #';',(a0,d0.w)
  8303.         beq.b    .ends
  8304.         cmp.b    #')',(a0,d0.w)
  8305.         beq.b    .ends
  8306.         cmp.b    #$20,(a0,d0.w)
  8307.         bne.b    .cops
  8308. .ends        sf    (a1)
  8309.  
  8310. .noleft
  8311. .nos
  8312.         movem.l    (a7)+,d0-a6
  8313.  
  8314.         subq.w    #1,time_cursor
  8315.         bpl.b    no_cursor
  8316.         sf    nosnap
  8317.         move.w    #15,time_cursor
  8318.         bsr.b    set_cursor
  8319. .no_cur        rts
  8320.  
  8321. set_cursor:    movem.l    d0/a0,-(a7)
  8322.         move.l    pic_ptr,a0
  8323.         add.w    cursor_x,a0
  8324.         move.w    cursor_y,d0
  8325.         mulu    #80*h,d0
  8326.         add.l    d0,a0
  8327.         not.b    cursor_on
  8328.         tst.b    no_print
  8329.         bne.b    .no
  8330.         not.b    (a0)
  8331.         not.b    80(a0)
  8332.         not.b    160(a0)
  8333.         not.b    240(a0)
  8334.         not.b    320(a0)
  8335.         not.b    400(a0)
  8336.         not.b    480(a0)
  8337.         not.b    560(a0)
  8338. .no        movem.l    (a7)+,d0/a0
  8339. no_cursor    rts
  8340.  
  8341. clear_cursor:    movem.l    d0/a0,-(a7)
  8342.         st    nosnap
  8343.         bsr    clear_snap
  8344.  
  8345.         move.w    #15,time_cursor
  8346.         move.l    pic_ptr,a0
  8347.         add.w    cursor_x,a0
  8348.         move.w    cursor_y,d0
  8349.         mulu    #80*h,d0
  8350.         add.l    d0,a0
  8351.         tst.b    cursor_on
  8352.         beq.b    no_clear_curs
  8353.         tst.b    no_print
  8354.         bne.b    .no
  8355.         not.b    (a0)
  8356.         not.b    80(a0)
  8357.         not.b    160(a0)
  8358.         not.b    240(a0)
  8359.         not.b    320(a0)
  8360.         not.b    400(a0)
  8361.         not.b    480(a0)
  8362.         not.b    560(a0)
  8363. .no
  8364. no_clear_curs    sf    cursor_on
  8365.         movem.l    (a7)+,d0/a0
  8366.         rts
  8367.  
  8368. snap_x:        dc.w 40
  8369. snap_y:        dc.w 10
  8370. snap_buf:    dcb.b 84,0
  8371. snap:        dc.b 0
  8372. nosnap:        dc.b 0
  8373.         even
  8374.  
  8375. clear_snap:    movem.l    d0-d2/a0,-(a7)
  8376.         move.w    sr,d2
  8377.         move.w    #$2700,sr
  8378.         tst.b    snap
  8379.         beq.b    .snapoff
  8380.         sf    snap
  8381.         move.l    pic_ptr,a0
  8382.         add.w    snap_x,a0
  8383.         move.w    snap_y,d0
  8384.         mulu    #80*h,d0
  8385.         add.l    d0,a0
  8386.         move.b    #$55,d0
  8387.         move.b    #$aa,d1
  8388.         eor.b    d0,(a0)
  8389.         eor.b    d1,80(a0)
  8390.         eor.b    d0,160(a0)
  8391.         eor.b    d1,240(a0)
  8392.         eor.b    d0,320(a0)
  8393.         eor.b    d1,400(a0)
  8394.         eor.b    d0,480(a0)
  8395.         eor.b    d1,560(a0)
  8396. .snapoff    move.w    d2,sr
  8397.         movem.l    (a7)+,d0-d2/a0
  8398.         rts
  8399.  
  8400. set_snap:    movem.l    d0-d2/a0,-(a7)
  8401.         tst.b    nosnap
  8402.         bne.b    .nosnap
  8403.         move.w    sr,d2
  8404.         move.w    #$2700,sr
  8405.         tst.b    snap
  8406.         bne.b    .snapon
  8407.         st    snap
  8408.         move.l    pic_ptr,a0
  8409.         add.w    snap_x,a0
  8410.         move.w    snap_y,d0
  8411.         mulu    #80*h,d0
  8412.         add.l    d0,a0
  8413.         move.b    #$55,d0
  8414.         move.b    #$aa,d1
  8415.         eor.b    d0,(a0)
  8416.         eor.b    d1,80(a0)
  8417.         eor.b    d0,160(a0)
  8418.         eor.b    d1,240(a0)
  8419.         eor.b    d0,320(a0)
  8420.         eor.b    d1,400(a0)
  8421.         eor.b    d0,480(a0)
  8422.         eor.b    d1,560(a0)
  8423. .snapon        move.w    d2,sr
  8424. .nosnap        movem.l    (a7)+,d0-d2/a0
  8425.         rts
  8426.  
  8427. ;-------------- Print an hex number -------------------
  8428.  
  8429. ;-> d0=hex number
  8430. ;-> d1=nb ascIIs (length of hex number)
  8431.  
  8432. print_hex    move.l    a0,-(a7)
  8433.         lea.l    general_txt,a0
  8434.         bsr.w    conv_hex
  8435.         sf    (a0,d1.w)        ;set end CHAR
  8436.         bsr    print
  8437.         move.l    (a7)+,a0
  8438.         rts
  8439.  
  8440. ;-------------- Print an hex number followed by a CR -
  8441.  
  8442. ;-> d0=hex number
  8443. ;-> d1=nb ascIIs (length of hex number)
  8444.  
  8445. print_hexCR    move.l    a0,-(a7)
  8446.         lea.l    general_txt,a0
  8447.         bsr.b    conv_hex
  8448.         move.b    #$a,(a0,d1.w)        ;set CR CHAR
  8449.         sf    1(a0,d1.w)        ;set end CHAR
  8450.         bsr    print
  8451.         move.l    (a7)+,a0
  8452.         rts
  8453.  
  8454. ;-------------- Print a decimal number --------------------
  8455.  
  8456. ;-> d0=dec number
  8457. ;-> d1=nb ascIIs    ;bit7=show zero
  8458.  
  8459. print_dec    movem.l    d0/a0,-(a7)
  8460.         lea.l    general_txt,a0
  8461.         bsr.b    conv_dec
  8462.         lea.l    general_txt,a0
  8463.         and.w    #$7f,d1
  8464.         sf    1(a0,d1.w)        ;set end CHAR
  8465.         bsr    print
  8466.         movem.l    (a7)+,d1/a0
  8467.         rts
  8468.  
  8469. ;-------------- Print a decimal number followed by a CR ---
  8470.  
  8471. ;-> d0=dec number
  8472. ;-> d1=nb ascIIs    ;bit7=show zero
  8473.  
  8474. print_decCR    movem.l    d0/a0,-(a7)
  8475.         lea.l    general_txt,a0
  8476.         bsr.b    conv_dec
  8477.         lea.l    general_txt,a0
  8478.         and.w    #$7f,d1
  8479.         move.b    #$a,1(a0,d1.w)        ;set CR CHAR
  8480.         sf    2(a0,d1.w)        ;set end CHAR
  8481.         bsr    print
  8482.         movem.l    (a7)+,d1/a0
  8483.         rts
  8484.  
  8485. ;-------------- Convert hex to ascII ------------------
  8486. ;-> d0=hex number
  8487. ;-> d1=nb ascIIs (length of hex number)
  8488. ;-> a0=ptr on ascII destination buffer
  8489.  
  8490. conv_hex    movem.l    d0-d2/a1,-(a7)
  8491.         and.w    #$007f,d1        ;clear bit 7
  8492.         lea.l    hex_list,a1
  8493.         subq.w    #1,d1
  8494. .do_conv_hex    move.w    d0,d2
  8495.         and.w    #$f,d2
  8496.         move.b    (a1,d2.w),(a0,d1.w)
  8497.         lsr.l    #4,d0
  8498.         dbf    d1,.do_conv_hex
  8499.         movem.l    (a7)+,d0-d2/a1
  8500.         rts
  8501.  
  8502. ;-------------- Convert dec to ascII ------------------
  8503. ;d0=dec number
  8504. ;d1=nb ascIIs        bit7=show zero
  8505. ;a0=ptr on ascII buffer
  8506.  
  8507. conv_dec:    movem.l    d0-d4/a1,-(a7)
  8508.  
  8509.         btst    #7,d1
  8510.         sne    d3
  8511.         and.w    #$003f,d1
  8512.  
  8513.         lea.l    dec_list,a1
  8514.         neg.w    d1
  8515.         add.w    #10,d1
  8516.         lsl.w    #2,d1
  8517.         add.w    d1,a1
  8518.  
  8519.         move.b    #' ',d4
  8520.         tst.l    d0
  8521.         bpl.b    .no_minus
  8522.         neg.l    d0
  8523.         move.b    #'-',d4
  8524.  
  8525. .no_minus    move.b    #' ',(a0)+
  8526.         move.l    d0,d2
  8527. .next        moveq    #0,d0
  8528.         move.l    (a1)+,d1
  8529.         beq.b    .end_dec
  8530. .loop        cmp.l    d2,d1
  8531.         bgt.b    .ok_dix
  8532.         sub.l    d1,d2
  8533.         addq.l    #1,d0
  8534.         bra.b    .loop
  8535. .ok_dix        subq.l    #1,d1
  8536.         bne.b    .no_last
  8537.         tst.b    d3
  8538.         bne.b    .no_last
  8539.         st    d3
  8540.         move.b    d4,-1(a0)
  8541. .no_last    tst.b    d3
  8542.         bne.b    .no_first
  8543.         st    d3
  8544.         tst.b    d0
  8545.         beq.b    .empty
  8546.         move.b    d4,-1(a0)
  8547.         bra.b    .no_first
  8548. .empty        sf    d3
  8549.         move.b    #' ',d0
  8550.         bra.b    .ok_spc
  8551. .no_first    cmp.b    #9,d0
  8552.         bls.b    .ok_dec
  8553.         moveq    #0,d0
  8554. .ok_dec        add.b    #'0',d0
  8555. .ok_spc        move.b    d0,(a0)+
  8556.         bra.b    .next
  8557.  
  8558. .end_dec    movem.l    (a7)+,d0-d4/a1
  8559.         rts
  8560.  
  8561.         cnop 0,4
  8562. dec_list    dc.l 1000000000
  8563.         dc.l 100000000
  8564.         dc.l 10000000
  8565.         dc.l 1000000
  8566.         dc.l 100000
  8567.         dc.l 10000
  8568.         dc.l 1000
  8569.         dc.l 100
  8570.         dc.l 10
  8571.         dc.l 1
  8572.         dc.l 0
  8573.  
  8574. **********************************************************
  8575.  
  8576. init_ascII    movem.l    d0-d2/a1-a3,-(a7)
  8577.         lea.l    ascII_conv,a1
  8578.  
  8579.         move.w    #256-1,d0
  8580.         moveq    #0,d1
  8581.  
  8582. loop_ia        lea.l    ascII,a2
  8583.         move.w    #end_ascII-ascII-1,d2
  8584. seek_ascII_i    cmp.b    (a2)+,d1
  8585.         dbeq    d2,seek_ascII_i
  8586.  
  8587.         lea.l    ascII+1,a3
  8588.         sub.l    a3,a2
  8589.         move.w    a2,d2
  8590.         move.b    d2,(a1)+
  8591.         addq.w    #1,d1
  8592.         dbf    d0,loop_ia
  8593.  
  8594.         movem.l    (a7)+,d0-d2/a1-a3
  8595.         rts
  8596.  
  8597. **************************************************************************
  8598.  
  8599. ;save DMA disk buffer to backup_dma
  8600. ;-> a0=buffer chip address
  8601.  
  8602. save_buffer    movem.l    d0-d1/a0-a1,-(a7)
  8603.         move.l    a0,buffer
  8604.         lea.l    backup_pic+$100,a1
  8605.         tst.b    pic_status
  8606.         beq.b    .oklow
  8607.         lea.l    $100.w,a1
  8608. .oklow        move.w    #($1a00*2)/4-1,d1
  8609. .exg        move.l    (a0)+,(a1)+
  8610.         dbf    d1,.exg
  8611.         movem.l    (a7)+,d0-d1/a0-a1
  8612.         rts
  8613.  
  8614. rest_buffer    movem.l    d0-d1/a0-a1,-(a7)
  8615.         move.l    buffer,a1
  8616.         lea.l    backup_pic+$100,a0
  8617.         tst.b    pic_status
  8618.         beq.b    .oklow
  8619.         lea.l    $100.w,a0
  8620. .oklow        move.w    #($1a00*2)/4-1,d1
  8621. .exg        move.l    (a0)+,(a1)+
  8622.         dbf    d1,.exg
  8623.         movem.l    (a7)+,d0-d1/a0-a1
  8624.         rts
  8625.  
  8626. ***********************************************************
  8627.  
  8628. ;-------------- read a single sector from floppy disk -----
  8629.  
  8630. ;-> d0=no of sector to read
  8631. ;-> a0=address to copy sector into
  8632.  
  8633. read_fsector    movem.l    d0-d7/a0-a4,-(a7)
  8634.  
  8635.         lea.l    backup_pic+$100+$1a00*2,a1
  8636.         tst.b    pic_status
  8637.         beq.b    .golow
  8638.         lea.l    $100+$1a00*2,a1
  8639.         st    no_print
  8640.         st    small_pic
  8641. .golow        move.l    a1,track_buffer
  8642.  
  8643.         move.l    a0,a3
  8644.  
  8645.         moveq    #0,d2
  8646.         move.w    d0,d2
  8647.         divu    #11,d2            ;d2=track_no of sector to read
  8648.         cmp.w    track_buffer_no,d2    ;is track_buffer ok ?
  8649.         bne.b    .notsame
  8650.  
  8651. .okaccess    lea.l    track_sector,a0
  8652.         move.l    d2,d0
  8653.         swap    d0
  8654.         tst.b    (a0,d0.w)        ;sector is in buffer ?
  8655.         bne.b    .notsame
  8656.  
  8657.         mulu    #512,d0            ;offset in track_buffer
  8658.         move.l    track_buffer,a0
  8659.  
  8660.         add.l    d0,a0
  8661.         moveq    #512/8-1,d0
  8662. .copysector    move.l    (a0)+,(a3)+
  8663.         move.l    (a0)+,(a3)+
  8664.         dbf    d0,.copysector
  8665.         bra.b    .okread
  8666.  
  8667. .notsame    bsr    write_flush
  8668.         move.w    d2,track_buffer_no
  8669.         move.w    d2,d0
  8670.         mulu    #11,d0
  8671.         lea.l    track_sector,a0
  8672.         clr.l    (a0)+            ;all sectors
  8673.         clr.l    (a0)+            ;are
  8674.         clr.l    (a0)+            ;loaded
  8675.         move.l    track_buffer,a0
  8676.         moveq    #11,d1            ;read 11 sectors (one track)
  8677.         moveq    #0,d7            ;read command
  8678.         bsr    access            ;read the track in track_buffer
  8679.         beq.b    .okaccess        ;no error ?
  8680.  
  8681.         moveq    #-1,d0
  8682.         move.w    d0,track_buffer_no    ;an error occured
  8683.         lea.l    track_sector,a0
  8684.         move.l    d0,(a0)+        ;all sectors
  8685.         move.l    d0,(a0)+        ;are
  8686.         move.l    d0,(a0)+        ;NOT loaded
  8687.  
  8688. .okread        tst.w    drive_err
  8689.         movem.l    (a7)+,d0-d7/a0-a4
  8690.         rts
  8691.  
  8692. ;-------------- write a single sector to floppy disk ------
  8693.  
  8694. ;-> d0=no of sector to write
  8695. ;-> a0=address to copy sector from
  8696.  
  8697. write_fsector    movem.l    d0-d7/a0-a4,-(a7)
  8698.  
  8699.         lea.l    backup_pic+$100+$1a00*2,a1
  8700.         tst.b    pic_status
  8701.         beq.b    .golow
  8702.         lea.l    $100+$1a00*2,a1
  8703.         st    no_print
  8704.         st    small_pic
  8705. .golow        move.l    a1,track_buffer
  8706.  
  8707.         move.l    a0,a3
  8708.  
  8709.         moveq    #0,d2
  8710.         move.w    d0,d2
  8711.         divu    #11,d2            ;d2=track_no of sector to write
  8712.         cmp.w    track_buffer_no,d2    ;is track_buffer ok ?
  8713.         beq.b    .oksame
  8714.  
  8715. .notsame    bsr.b    write_flush
  8716.         move.w    d2,track_buffer_no
  8717.         moveq    #-1,d0
  8718.         lea.l    track_sector,a0
  8719.         move.l    d0,(a0)+        ;all sectors
  8720.         move.l    d0,(a0)+        ;are
  8721.         move.l    d0,(a0)+        ;NOT loaded
  8722.  
  8723. .oksame        move.l    d2,d0
  8724.         swap    d0
  8725.         lea.l    track_sector,a0
  8726.         sf    (a0,d0.w)        ;set sector as loaded in buffer
  8727.         mulu    #512,d0
  8728.         move.l    track_buffer,a0
  8729.         add.l    d0,a0
  8730.         moveq    #512/8-1,d0
  8731. .copysector    move.l    (a3)+,(a0)+
  8732.         move.l    (a3)+,(a0)+
  8733.         dbf    d0,.copysector
  8734.  
  8735.         st    flush_needed
  8736.  
  8737.         tst.w    drive_err
  8738.         movem.l    (a7)+,d0-d7/a0-a4
  8739.         rts
  8740.  
  8741. ;-------------- flush write buffer for floppy disk --------
  8742.  
  8743. write_flush    movem.l    d0-d7/a0-a4,-(a7)
  8744.  
  8745.         lea.l    backup_pic+$100+$1a00*2,a1
  8746.         tst.b    pic_status
  8747.         beq.b    .golow
  8748.         lea.l    $100+$1a00*2,a1
  8749.         st    no_print
  8750.         st    small_pic
  8751. .golow        move.l    a1,track_buffer
  8752.  
  8753.         tst.w    track_buffer_no
  8754.         bmi.w    .noflush
  8755.  
  8756.         tst.b    flush_needed
  8757.         beq.w    .noflush
  8758.  
  8759. .recheck    lea.l    track_sector,a0
  8760.         lea.l    11(a0),a1        ;end of sectors list
  8761.         moveq    #-1,d2
  8762.         moveq    #11-1,d0
  8763. .seek        addq.l    #1,d2
  8764.         tst.b    (a0)+
  8765.         dbne    d0,.seek
  8766.         beq.b    .goflush
  8767.  
  8768.         moveq    #0,d1            ;d1=nb sectors to read
  8769.         subq.l    #1,a0
  8770. .link        sf    (a0)+            ;set sector as loaded
  8771.         addq.l    #1,d1
  8772.         cmp.l    a1,a0
  8773.         beq.b    .okread
  8774.         tst.b    (a0)
  8775.         bne.b    .link
  8776.  
  8777. .okread        cmp.w    #11,d1
  8778.         beq.b    .noflush
  8779.         move.l    track_buffer,a0
  8780.         move.w    track_buffer_no,d0
  8781.         mulu    #11,d0
  8782.         add.w    d2,d0
  8783.         mulu    #512,d2
  8784.         add.l    d2,a0
  8785.         moveq    #0,d7            ;read command
  8786.         bsr    access
  8787.         bne.b    .error
  8788.         bra.b    .recheck
  8789.  
  8790. .goflush    move.w    track_buffer_no,d0
  8791.         mulu    #11,d0
  8792.         move.l    track_buffer,a0
  8793.         moveq    #11,d1            ;write 11 sectors (one track)
  8794.         moveq    #-1,d7            ;write command
  8795.         bsr    access
  8796.         beq.b    .noerr
  8797.  
  8798. .error        moveq    #-1,d0
  8799.         move.w    d0,track_buffer_no    ;an error occured
  8800.         lea.l    track_sector,a0
  8801.         move.l    d0,(a0)+        ;all sectors
  8802.         move.l    d0,(a0)+        ;are
  8803.         move.l    d0,(a0)+        ;NOT loaded
  8804.  
  8805. .noerr
  8806. .noflush    sf    flush_needed
  8807.  
  8808.         tst.w    drive_err
  8809.         movem.l    (a7)+,d0-d7/a0-a4
  8810.         rts
  8811.  
  8812. ;-------------- write multiple sectors to floppy ----------
  8813. ;-------------- exg pic memory and stop interrupts --------
  8814. ;-> d0=first sector
  8815. ;-> d1=nb of sector
  8816. ;-> a0=address
  8817.  
  8818. write        movem.l    d0-d1/a0,-(a7)
  8819.         tst.w    d1
  8820.         beq.b    .nosave
  8821.         bsr    remove_pic
  8822. .loop        bsr    write_fsector
  8823.         addq.w    #1,d0
  8824.         lea.l    512(a0),a0
  8825.         subq.w    #1,d1
  8826.         bne.b    .loop
  8827.         bsr    write_flush
  8828.         bsr    set_pic
  8829. .nosave        tst.w    drive_err
  8830.         movem.l    (a7)+,d0-d1/a0
  8831.         rts
  8832.  
  8833. ;-------------- read multiple sectors from floppy ---------
  8834. ;-------------- exg pic memory and restore interrupts -----
  8835.  
  8836. ;-> d0=first sector
  8837. ;-> d1=nb of sector
  8838. ;-> a0=address
  8839.  
  8840. read        movem.l    d0-d1/a0,-(a7)
  8841.         tst.w    d1
  8842.         beq.b    .noread
  8843.         bsr    remove_pic
  8844. .loop        bsr    read_fsector
  8845.         addq.w    #1,d0
  8846.         lea.l    512(a0),a0
  8847.         subq.w    #1,d1
  8848.         bne.b    .loop
  8849.         bsr    set_pic
  8850. .noread        tst.w    drive_err
  8851.         movem.l    (a7)+,d0-d1/a0
  8852.         rts
  8853.  
  8854. ;-------------- write multiple sectors to floppy ----------
  8855.  
  8856. ;-> d0=first sector
  8857. ;-> d1=nb of sector
  8858. ;-> a0=address
  8859.  
  8860. write2        movem.l    d0-d1/a0,-(a7)
  8861.         tst.w    d1
  8862.         beq.b    .nosave
  8863. .loop        bsr    write_fsector
  8864.         addq.w    #1,d0
  8865.         lea.l    512(a0),a0
  8866.         subq.w    #1,d1
  8867.         bne.b    .loop
  8868.         bsr    write_flush
  8869. .nosave        tst.w    drive_err
  8870.         movem.l    (a7)+,d0-d1/a0
  8871.         rts
  8872.  
  8873. ;-------------- read multiple sectors from floppy ---------
  8874.  
  8875. ;-> d0=first sector
  8876. ;-> d1=nb of sector
  8877. ;-> a0=address
  8878.  
  8879. read2        movem.l    d0-d1/a0,-(a7)
  8880.         tst.w    d1
  8881.         beq.b    .noread
  8882. .loop        bsr    read_fsector
  8883.         addq.w    #1,d0
  8884.         lea.l    512(a0),a0
  8885.         subq.w    #1,d1
  8886.         bne.b    .loop
  8887. .noread        tst.w    drive_err
  8888.         movem.l    (a7)+,d0-d1/a0
  8889.         rts
  8890.  
  8891. ***********************************************
  8892. ;d0.w=start sector (if write then d0 MUST be a multiple of 11)
  8893. ;d1.w=nb sectors   (if write then d1 MUST be a multiple of 11)
  8894. ;d7: -1=write 0=read
  8895. ;a0=address to load/save
  8896.  
  8897. ;if d1=-1 & d7=-1 -> format whole disk
  8898.  
  8899. access:        movem.l    d0-a6,-(a7)
  8900.         lea.l    $dff000,a6
  8901.  
  8902.         lea.l    backup_pic+$100+$1a00*2,a1
  8903.         tst.b    pic_status
  8904.         beq.b    .golow
  8905.         lea.l    $100+$1a00*2,a1
  8906.         st    no_print
  8907.         st    small_pic
  8908. .golow        move.l    a1,track_buffer
  8909.  
  8910.         ext.l    d0
  8911.         ext.l    d1
  8912.  
  8913.         move.l    a0,a4            ;a4=address of actual sector
  8914.  
  8915.         lea.l    $40000,a0
  8916.         bsr    save_buffer
  8917.  
  8918.         sf    first_sauve
  8919.         tst.w    d1
  8920.         smi    format
  8921.         bpl.b    .no_format
  8922.         moveq    #0,d0
  8923.         move.w    #22*80,d1
  8924.         lea.l    track_sector,a0
  8925.         moveq    #-1,d5
  8926.         move.l    d5,(a0)+        ;all sectors
  8927.         move.l    d5,(a0)+        ;are NOT
  8928.         move.l    d5,(a0)+        ;loaded in track_buffer
  8929.         move.w    d5,track_buffer_no
  8930. .no_format
  8931.  
  8932.         move.w    d1,sectpos        ;nb sectors to read/write
  8933.  
  8934.         cmp.l    #-1,d7            ;write requested ?
  8935.         seq    writes
  8936.  
  8937.         ext.l    d0
  8938.         move.l    d0,d5
  8939.         divu    #11,d5            ;d5.w = start_track
  8940.         move.l    d5,d0
  8941.         swap    d0
  8942.         move.w    d0,startsec    ;nb sectors to skip in 1st track
  8943.  
  8944.         lea.l    $bfd100,a0
  8945.         move.w    #$8210,$96(a6)
  8946.  
  8947.         move.w    $10(a6),d0
  8948.         or.w    #$8000,d0
  8949.         move.w    d0,OldAdk
  8950.         move.w    #$7fff,$9e(a6)
  8951.         move.w    #$9100,$9e(a6)
  8952.         tst.b    writes
  8953.         bne.b    no_sync
  8954.         move.w    #$8400,$9e(a6)
  8955. no_sync:    move.w    #$4489,$7e(a6)
  8956.  
  8957.         bsr    motor_on        ;turn drive motor ON
  8958.         tst.w    drive_err
  8959.         bne.w    fin
  8960.         tst.b    writes
  8961.         beq.b    .read
  8962.         btst    #3,$bfe001        ;test if write protected
  8963.         bne.b    .read
  8964.         move.w    #WRITEPROTECT_ERR,drive_err
  8965.         bra.w    fin
  8966. .read
  8967.         bsr    inittete    ;init head pos (track 0) if needed
  8968.  
  8969.         move.w    drive,d0
  8970.         bclr    d0,(a0)
  8971.  
  8972.         move.w    d5,d0
  8973.         bsr    settete            ;move heads to 1st track
  8974.  
  8975.         sf    ctrl            ;clear end signal
  8976.  
  8977. next:        movem.l    d0-d1/a0/a3,-(a7)    ;check if there is a conflict
  8978.         move.l    buffer,d0        ;between the DMA buffer and
  8979.         move.l    d0,d1            ;the actual sector accessed
  8980.         add.l    #$1a00*2,d1
  8981.         lea.l    11*512(a4),a3
  8982.         cmp.l    d0,a3
  8983.         ble.b    .okbuf
  8984.         cmp.l    d1,a4
  8985.         bge.b    .okbuf
  8986.         bsr    rest_buffer
  8987.         move.l    #$60000,d1
  8988.         cmp.l    #$40000,d0
  8989.         beq.b    .go40
  8990.         move.l    #$40000,d1
  8991. .go40        move.l    d1,a0
  8992.         bsr    save_buffer
  8993. .okbuf        movem.l    (a7)+,d0-d1/a0/a3
  8994.  
  8995.         tst.b    writes
  8996.         beq.b    ok_read
  8997.         tst.w    startsec        ;if write then 1st sector
  8998.         bne.b    fin            ;must be a multiple of 11
  8999.         cmp.w    #11,sectpos        ;write at least 11 sectors
  9000.         blt.b    fin
  9001.         bsr    sauve
  9002.         bra.b    ok_sauve
  9003. ok_read:    bsr    charge
  9004.         tst.w    drive_err
  9005.         bne.b    fin
  9006. ok_sauve:    tst.b    ctrl            ;end of access ?
  9007.         bne.b    fin
  9008.         tst.b    break
  9009.         bne.b    fin
  9010.  
  9011.     ;    btst    #5,$bfe001        ;removed due to AT 1200 bug !
  9012.     ;    beq.b    .okspeed
  9013.     ;    move.w    #NODISK_ERR,drive_err
  9014.     ;    bra.b    fin
  9015.  
  9016. .okspeed    movem.l    d0/a1,-(a7)
  9017.         lea.l    track,a1
  9018.         move.w    drive,d0
  9019.         move.w    -3*2(a1,d0.w*2),d0    ;get previous track pos
  9020.         addq.w    #1,d0            ;step to next track or side
  9021.         bsr    settete
  9022.         movem.l    (a7)+,d0/a1
  9023.         bra.w    next
  9024.  
  9025. fin:        bsr    timer2
  9026.         bsr    rest_buffer
  9027.  
  9028.         move.w    drive,d0
  9029.         bset    d0,(a0)            ;deselect drive
  9030.         bsr    timer1
  9031.  
  9032.         move.w    #$7fff,$9e(a6)
  9033.         move.w    OldAdk,$9e(a6)
  9034.  
  9035.         tst.w    drive_err
  9036.         movem.l    (a7)+,d0-a6
  9037.         rts
  9038.  
  9039. *******************************
  9040.  
  9041. motor_on:    movem.l    d0/a0,-(a7)
  9042.         lea.l    $bfd100,a0
  9043.         move.w    drive,d0
  9044.         or.b    #$80,(a0)
  9045.         bset    d0,(a0)
  9046.         bsr    timer1
  9047.         and.b    #$7f,(a0)
  9048.         bsr    timer1
  9049.         bclr    d0,(a0)
  9050.         bsr    timer1
  9051.  
  9052.         btst    d0,mot_on
  9053.         bne.b    .already_on
  9054.  
  9055.         move.b    #0,$bfe801
  9056.  
  9057. .motor_wait    cmp.b    #30,$bfe801        ;wait > 500 ms
  9058.         bls.b    .motor_wait
  9059.  
  9060.         bset    d0,mot_on
  9061.  
  9062. .already_on    movem.l    (a7)+,d0/a0
  9063.         rts
  9064.  
  9065. ;Old code removed due to AT 1200 bug !
  9066.  
  9067. ;motor_wait:    cmp.b    #80,$bfe801
  9068. ;        bhi.b    .no_mot_on
  9069. ;        btst    #5,$bfe001
  9070. ;        bne.b    motor_wait
  9071. ;.out        movem.l    (a7)+,d0/a0
  9072. ;        rts
  9073.  
  9074. ;.no_mot_on    move.w    #NODISK_ERR,drive_err
  9075. ;        bra.b    .out
  9076.  
  9077. *******************************
  9078.  
  9079. motor_off:    bsr.w    rest_head
  9080.         movem.l    d0/a0,-(a7)
  9081.         lea.l    $bfd100,a0
  9082.         move.w    drive,d0
  9083.         bset    d0,(a0)
  9084.         bsr    timer1
  9085.         or.b    #$80,(a0)
  9086.         bsr    timer1
  9087.         bclr    d0,(a0)
  9088.         bsr    timer1
  9089.         bset    d0,(a0)
  9090.         bsr    timer1
  9091.         bclr    d0,mot_on
  9092.         movem.l    (a7)+,d0/a0
  9093.         rts
  9094.  
  9095. *******************************
  9096.  
  9097. ;>0.6 ms
  9098.  
  9099. timer1        movem.l    d0-d1/a6,-(a7)
  9100.         lea.l    $dff000,a6
  9101.         moveq    #10-1,d0
  9102. .loop        move.b    $6(a6),d1
  9103. .w1        cmp.b    $6(a6),d1
  9104.         beq.b    .w1
  9105.         dbf    d0,.loop
  9106.         movem.l    (a7)+,d0-d1/a6
  9107.         rts
  9108.  
  9109.  
  9110. ;>3 ms
  9111.  
  9112. timer2        movem.l    d0-d1/a6,-(a7)
  9113.         lea.l    $dff000,a6
  9114.         moveq    #50-1,d0
  9115. .loop        move.b    $6(a6),d1
  9116. .w1        cmp.b    $6(a6),d1
  9117.         beq.b    .w1
  9118.         dbf    d0,.loop
  9119.         movem.l    (a7)+,d0-d1/a6
  9120.         rts
  9121.  
  9122. ;>18 ms
  9123.  
  9124. timer3        movem.l    d0-d1/a6,-(a7)
  9125.         lea.l    $dff000,a6
  9126.         move.w    #284-1,d0
  9127. .loop        move.b    $6(a6),d1
  9128. .w1        cmp.b    $6(a6),d1
  9129.         beq.b    .w1
  9130.         dbf    d0,.loop
  9131.         movem.l    (a7)+,d0-d1/a6
  9132.         rts
  9133.  
  9134. *******************************
  9135.  
  9136. step_head:    bclr    #0,(a0)
  9137.         bsr    timer1
  9138.         bset    #0,(a0)
  9139.         bsr    timer2
  9140.         rts
  9141.  
  9142. *******************************
  9143.  
  9144. ;-------------- check which drive is present ----
  9145.  
  9146. test_drive    movem.l    d0-d3/a0-a2,-(a7)
  9147.         lea.l    $bfd100,a0
  9148.         lea.l    $bfe001,a1
  9149.         move.b    #$ff,(a0)
  9150.         lea.l    drive_present,a2
  9151.         st    (a2)+            ;DF0: always present
  9152.  
  9153.         moveq    #4,d0            ;drive1 SEL
  9154.  
  9155.         moveq    #3-1,d3            ;3 drives to test
  9156.  
  9157. .next_drive    and.b    #$7f,(a0)
  9158.         bsr    timer1
  9159.         bclr    d0,(a0)            ;switch drive ON
  9160.         bsr    timer1
  9161.         bset    d0,(a0)
  9162.         bsr    timer1
  9163.         or.b    #$80,(a0)
  9164.         bclr    d0,(a0)            ;switch drive OFF
  9165.         bsr    timer1
  9166.  
  9167.         moveq    #0,d1            ;d1=drive ID
  9168.         moveq    #32-1,d2
  9169. .loop        add.l    d1,d1
  9170.         btst    #5,(a1)            ;one bit of ID in RDY
  9171.         beq.b    .zero
  9172.         addq.l    #1,d1            ;read drive ID
  9173. .zero        bset    d0,(a0)            ;pulse SEL
  9174.         bsr    timer1
  9175.         bclr    d0,(a0)
  9176.         bsr    timer1
  9177.         dbf    d2,.loop
  9178.  
  9179.         bset    d0,(a0)            ;deselect drive
  9180.         bsr    timer1
  9181.  
  9182.         tst.l    d1
  9183.         seq    (a2)+
  9184.         addq.w    #1,d0            ;next drive
  9185.         dbf    d3,.next_drive
  9186.  
  9187.         movem.l    (a7)+,d0-d3/a0-a2
  9188.         rts
  9189.  
  9190. ******************************
  9191.  
  9192. ;-------------- init head pos -------------------
  9193.  
  9194. inittete:    movem.l    d0/a0-a1,-(a7)
  9195.         lea.l    $bfd100,a0
  9196.         move.w    drive,d0
  9197.         btst    d0,init        ;test if the selected drive was inited
  9198.         bne.b    .no_init
  9199.         bclr    d0,(a0)
  9200.         lea.l    old_head,a1
  9201.         clr.w    -3*2(a1,d0.w*2)    ;save old position of head here
  9202.         bset    #1,(a0)
  9203.         bsr    timer1
  9204.  
  9205. .cont00        btst    #4,$bfe001
  9206.         beq.b    .track00
  9207.         bsr.w    step_head
  9208.         addq.w    #2,-3*2(a1,d0.w*2)
  9209.         bra.b    .cont00
  9210.  
  9211. .track00    lea.l    track,a1
  9212.         clr.w    -3*2(a1,d0.w*2)    ;current head pos = 0
  9213.         bset    d0,init
  9214.         bset    d0,(a0)
  9215.  
  9216. .no_init    movem.l    (a7)+,d0/a0-a1
  9217.         rts
  9218.  
  9219. rest_head    movem.l    d0-d1/a1,-(a7)
  9220.         move.w    drive,d0
  9221.         btst    d0,init
  9222.         beq.b    .no_rest
  9223.         lea.l    $bfd100,a0
  9224.         bclr    d0,(a0)
  9225.         bsr    timer1
  9226.         bclr    d0,init
  9227.         lea.l    old_head,a1
  9228.         move.w    -3*2(a1,d0.w*2),d0
  9229.         bsr    timer1
  9230.         bsr    settete
  9231.         move.w    drive,d0
  9232.         lea.l    track,a1
  9233.         move.w    #-1,-3*2(a1,d0.w*2)
  9234.         bset    d0,(a0)
  9235. .no_rest    movem.l    (a7)+,d0-d1/a1
  9236.         rts
  9237.  
  9238. *******************************
  9239.  
  9240. ;d0=track to reach (0-159)
  9241.  
  9242. settete:    movem.l    d0-d4,-(a7)
  9243.         sf    d4
  9244.         bsr    timer1
  9245.         move.l    a1,-(a7)
  9246.         lea.l    track,a1
  9247.         move.w    drive,d1
  9248.         move.w    -3*2(a1,d1.w*2),d1    ;get old pos of heads
  9249.         move.l    (a7)+,a1
  9250.         move.w    d0,d3            ;new pos
  9251.         asr.w    #1,d0
  9252.         asr.w    #1,d1
  9253.         cmp.w    d0,d1
  9254.  
  9255.         blt.b    moinstete
  9256.         bset    #1,(a0)            ;set dir
  9257.         sub.w    d0,d1
  9258.         move.w    d1,d0
  9259.         moveq    #-2,d2
  9260.         bra.b    go_dbf
  9261.  
  9262. moinstete:    bclr    #1,(a0)            ;set dir
  9263.         sub.w    d1,d0
  9264.         moveq    #2,d2
  9265.         bra.b    go_dbf
  9266.  
  9267. loop_set:    bsr.w    step_head
  9268.         st    d4
  9269.  
  9270. go_dbf:        dbf    d0,loop_set
  9271.  
  9272.         move.l    a1,-(a7)
  9273.         move.w    drive,d0
  9274.         lea.l    track,a1
  9275.         move.w    d3,-3*2(a1,d0.w*2)    ;set new pos of heads
  9276.         move.l    (a7)+,a1
  9277.         and.w    #1,d3
  9278.         bne.b    impair
  9279.         bset    #2,(a0)
  9280.         bra.b    pair
  9281. impair:        bclr    #2,(a0)
  9282. pair:        bsr    timer2
  9283.  
  9284.         tst.b    d4
  9285.         beq.b    .nomove
  9286.         bsr    timer3
  9287. .nomove
  9288.         movem.l    (a7)+,d0-d4
  9289.         rts
  9290.  
  9291. ***************************************
  9292.  
  9293. charge:        movem.l    d0/d7/a3,-(a7)
  9294.         moveq    #5-1,d7
  9295. .loop        move.w    #$4000,$24(a6)
  9296.         bsr    timer1
  9297.         move.l    buffer,a3
  9298.         move.l    a3,$20(a6)
  9299.         move.w    #$9a00,d0        ;len=$1a00*2=$3400
  9300.         move.w    #2,$9c(a6)
  9301.         move.w    d0,$24(a6)
  9302.         move.w    d0,$24(a6)
  9303.  
  9304.         move.b    #0,$bfe801
  9305.  
  9306. .waitdmad    cmp.b    #100,$bfe801        ;wait no more than 2s
  9307.         bhi.b    .error
  9308.         move.w    $1e(a6),d0
  9309.         and.w    #2,d0
  9310.         beq.b    .waitdmad
  9311.  
  9312.         move.w    #$4000,$24(a6)
  9313.  
  9314.         bsr.b    dmfm
  9315.         beq.b    .out
  9316.         dbf    d7,.loop        ;retry
  9317.  
  9318. .error        move.w    #TRACKCORRUPT_ERR,drive_err    ;track corrupted
  9319. .out        movem.l    (a7)+,d0/d7/a3
  9320.         rts
  9321.  
  9322. ***************************************
  9323.  
  9324. dmfm:        movem.l    d0-d7/a0-a2,-(a7)
  9325.         move.l    #$55555555,d7
  9326.  
  9327.         move.l    a4,a0                ;save old status
  9328.         move.w    sectpos,oldsectpos
  9329.         move.w    startsec,oldstartsec
  9330.  
  9331.         moveq    #11-1,d4
  9332.         moveq    #0,d3
  9333.         move.l    a3,a1
  9334.         lea.l    $1a00*2(a1),a1
  9335.  
  9336. nextsector:    move.l    a3,a2
  9337.  
  9338. seek:        cmp.l    a1,a2
  9339.         bge.w    mfm_error
  9340.         cmp.w    #$4489,(a2)+
  9341.         bne.b    seek
  9342.         cmp.w    #$4489,(a2)
  9343.         beq.b    seek
  9344.         move.b    2(a2),D0
  9345.         move.b    6(a2),D1
  9346.         and.b    d7,d0
  9347.         and.b    d7,d1
  9348.         add.b    d0,d0
  9349.         or.b    d1,d0
  9350.         cmp.b    d0,d3
  9351.         beq.b    oksec
  9352.         lea.l    $43e(a2),a2
  9353.         bra.b    seek
  9354. oksec:        addq.l    #1,d3
  9355.  
  9356.         lea.l    $0028(a2),a2
  9357.  
  9358.         move.l    (a2)+,d0
  9359.         move.l    (a2)+,d1
  9360.         and.l    d7,d0
  9361.         and.l    d7,d1
  9362.         add.l    d0,d0
  9363.         or.l    d1,d0
  9364.         move.l    d0,d6
  9365.  
  9366.         move.l    a2,-(a7)
  9367.         lea.l    -$30(a2),a2
  9368.  
  9369.         moveq    #0,d0
  9370.         moveq    #$0a-1,d5
  9371. .nextcheck:    move.l    (a2)+,d1
  9372.         eor.l    d1,d0
  9373.         dbf    d5,.nextcheck
  9374.  
  9375.         move.l    (a7)+,a2
  9376.  
  9377.         and.l    d7,d0
  9378.         cmp.l    d6,d0        ;test header checksum
  9379.         bne.w    mfm_error
  9380.  
  9381.         move.l    (a2)+,d0
  9382.         move.l    (a2)+,d1
  9383.         and.l    d7,d0
  9384.         and.l    d7,d1
  9385.         add.l    d0,d0
  9386.         or.l    d1,d0
  9387.         move.l    d0,d6
  9388.  
  9389.         move.l    a2,-(a7)
  9390.  
  9391.         moveq    #0,d0
  9392.         move.w    #$100/4-1,d5
  9393. .nextcheck2:    move.l    (a2)+,d1
  9394.         eor.l    d1,d0
  9395.         move.l    (a2)+,d1
  9396.         eor.l    d1,d0
  9397.         move.l    (a2)+,d1
  9398.         eor.l    d1,d0
  9399.         move.l    (a2)+,d1
  9400.         eor.l    d1,d0
  9401.         dbf    d5,.nextcheck2
  9402.  
  9403.         move.l    (a7)+,a2
  9404.  
  9405.         and.l    d7,d0
  9406.         cmp.l    d6,d0        ;test data checksum
  9407.         bne.b    mfm_error
  9408.  
  9409.         tst.w    sectpos        ;all sectors loaded ?
  9410.         beq.b    pasokload
  9411.         tst.w    startsec;have we reached the 1st sector to load ?
  9412.         beq.b    okloadsec
  9413.         subq.w    #1,startsec
  9414.         bra.b    pasokload
  9415.  
  9416. okloadsec:    moveq    #$80-1,d5
  9417. decodemfm:    move.l    $200(a2),d1
  9418.         move.l    (a2)+,d0
  9419.         and.l    d7,d0
  9420.         and.l    d7,d1
  9421.         add.l    d0,d0
  9422.         or.l    d1,d0
  9423.         move.l    d0,(a4)+
  9424.         dbf    d5,decodemfm
  9425.  
  9426.         subq.w    #1,sectpos    ;nb sectors to load --
  9427.         bne.b    pasokload
  9428.         st    ctrl        ;set end signal
  9429.         bra.b    reload
  9430.  
  9431. pasokload:    dbf    d4,nextsector
  9432.  
  9433. reload:        movem.l    (a7)+,d0-d7/a0-a2
  9434.         moveq    #0,d0            ;ok
  9435.         rts
  9436.  
  9437. mfm_error:    move.w    oldsectpos,sectpos    ;restore status
  9438.         move.w    oldstartsec,startsec
  9439.         move.l    a0,a4
  9440.         movem.l    (a7)+,d0-d7/a0-a2
  9441.         moveq    #-1,d0            ;an error occured
  9442.         rts
  9443.  
  9444. ***************************************************
  9445.  
  9446. sauve:        bsr.b    code_mfm
  9447.  
  9448.         move.w    #$4000,$24(a6)
  9449.         bsr    timer2
  9450.         move.l    buffer,a3
  9451.         move.l    a3,$20(a6)
  9452.         move.w    #$c000+$220*11+$2a0,d0
  9453.         move.w    #2,$9c(a6)
  9454.         move.w    d0,$24(a6)
  9455.         move.w    d0,$24(a6)
  9456.  
  9457. waitdmad2:    move.w    $1e(a6),d0
  9458.         and.w    #2,d0
  9459.         beq.b    waitdmad2
  9460.  
  9461.         move.w    #$4000,$24(a6)
  9462.  
  9463.         bsr    timer2
  9464.  
  9465.         rts
  9466.  
  9467. ***********************************
  9468. ;Code track
  9469. ;-> a4=data to be coded
  9470.  
  9471. code_mfm:    movem.l    a0-a3/d0-d7,-(a7)
  9472.  
  9473.         lea.l    track,a3
  9474.         move.w    drive,d0
  9475.         move.w    -3*2(a3,d0.w*2),d0    ;get track no
  9476.  
  9477.         move.l    buffer,a3
  9478.  
  9479.         move.l    #$55555555,d5
  9480.         move.l    d5,d6
  9481.         add.l    d6,d6            ;d6=$aaaaaaaa
  9482.  
  9483.         tst.b    format
  9484.         beq.b    .noformat
  9485.         tst.b    first_sauve
  9486.         bne.b    .fast
  9487.  
  9488. .noformat    move.w    #$1a00*2/16-1,d1
  9489. .filla        move.l    d6,(a3)+
  9490.         move.l    d6,(a3)+
  9491.         move.l    d6,(a3)+
  9492.         move.l    d6,(a3)+
  9493.         dbf    d1,.filla
  9494.  
  9495. .fast        move.l    buffer,a3
  9496.         lea.l    $1a00*2-$440*11-$20(a3),a3
  9497.  
  9498.         bsr.b    do_track
  9499.  
  9500.         st    first_sauve
  9501.         movem.l    (a7)+,a0-a3/d0-d7
  9502.         rts
  9503.  
  9504. *******************************
  9505. ;-> a3=ptr on dest track
  9506. ;-> a4=ptr on data to write
  9507. ;-> d0=no of track
  9508.  
  9509. do_track:    move.b    d0,header+1
  9510.         move.w    #$000b,header+2
  9511.         moveq    #11-1,d4
  9512. next_sec:    bsr.b    code_sector
  9513.         lea.l    $220*2(a3),a3        ;go next sector
  9514.         add.w    #$00ff,header+2        ;inc actual sec, dec sec left
  9515.         subq.w    #1,sectpos
  9516.         dbf    d4,next_sec
  9517.  
  9518.         tst.w    sectpos
  9519.         bne.b    .noend
  9520.         st    ctrl            ;set end signal
  9521. .noend        rts
  9522.  
  9523. *******************************
  9524.  
  9525. code_sector    move.l    a3,a0
  9526.         addq.l    #4,a0
  9527.         move.l    #$44894489,(a0)+    ;sync
  9528.         move.l    header,d0
  9529.         bsr.w    code
  9530.  
  9531.         lea.l    8(a3),a0
  9532.         moveq    #10,d1
  9533.         bsr.w    chk_sum
  9534.         bsr.b    code
  9535.  
  9536.         tst.b    format
  9537.         beq.b    .no_format
  9538.         move.l    track_buffer,a4
  9539.         tst.b    first_sauve
  9540.         bne.b    .out
  9541.         moveq    #0,d0
  9542.         move.w    #512/16-1,d7
  9543. .clear        move.l    d0,(a4)+
  9544.         move.l    d0,(a4)+
  9545.         move.l    d0,(a4)+
  9546.         move.l    d0,(a4)+
  9547.         dbf    d7,.clear
  9548.         move.l    track_buffer,a4
  9549.         move.l    #$444f5301,(a4)        ;'DOS',1 = FFS
  9550. .no_format
  9551.         addq.l    #8,a0
  9552.         moveq    #$80-1,d7
  9553. .code_sec:    move.l    (a4)+,d0
  9554.  
  9555.         move.l    d0,d3
  9556.         lsr.l    #1,d0
  9557.         bsr.w    coder2
  9558.  
  9559.         lea.l    $200-4(a0),a0
  9560.         move.l    d3,d0
  9561.         bsr.w    coder2
  9562.         lea.l    -$200(a0),a0
  9563.  
  9564.         dbf    d7,.code_sec
  9565.  
  9566.         lea.l    $40(a3),a0
  9567.         move.w    #$100,d1
  9568.         bsr.w    chk_sum2
  9569.         lea.l    $38(a3),a0
  9570.         bsr.b    code
  9571. .out        rts
  9572.  
  9573. *******************************
  9574. ; a0 = address du buffer code
  9575. ; d0 = long word to code
  9576.  
  9577. code:        movem.l    d2/d3,-(a7)
  9578.         move.l    d0,d3
  9579.         lsr.l    #1,d0
  9580.         bsr.b    coder
  9581.         move.l    d3,d0
  9582.         bsr.b    coder2
  9583.         movem.l    (a7)+,d2/d3
  9584.         rts    
  9585.  
  9586. *******************************
  9587.  
  9588. coder:        and.l    d5,d0
  9589.         move.l    d0,d2
  9590.         eor.l    d5,d2
  9591.         move.l    d2,d1
  9592.         add.l    d2,d2
  9593.         lsr.l    #1,d1
  9594.         bset    #31,d1
  9595.         and.l    d2,d1
  9596.         or.l    d1,d0
  9597.         btst    #0,-1(a0)
  9598.         beq.b    pas_bit
  9599.         bclr    #31,d0
  9600. pas_bit:    move.l    d0,(a0)+
  9601.         rts
  9602.  
  9603. *******************************
  9604.  
  9605. chk_sum:    move.l    d2,-(a7)
  9606.         subq.w    #1,d1
  9607.         moveq    #0,d0
  9608. l_chks:        move.l    (a0)+,d2
  9609.         eor.l    d2,d0
  9610.         dbf    d1,l_chks
  9611.         and.l    d5,d0
  9612.         move.l    (a7)+,d2
  9613.         rts
  9614.  
  9615. chk_sum2:    move.l    d2,-(a7)
  9616.         subq.w    #1,d1
  9617.         moveq    #0,d0
  9618. l_chks2:    move.l    (a0)+,d2
  9619.         eor.l    d2,d0
  9620.         dbf    d1,l_chks2
  9621.         move.l    (a7)+,d2
  9622.         and.l    d5,d0
  9623.         rts
  9624.  
  9625. *******************************
  9626.  
  9627. coder2:        and.l    d5,d0
  9628.         move.l    d0,d2
  9629.         eor.l    d5,d2
  9630.         move.l    d2,d1
  9631.         add.l    d2,d2
  9632.         lsr.l    #1,d1
  9633.         bset    #31,d1
  9634.         and.l    d2,d1
  9635.         or.l    d1,d0
  9636.         btst    #0,-1(a0)
  9637.         beq.b    pas_bitx
  9638.         bclr    #31,d0
  9639. pas_bitx:    move.l    d0,(a0)+
  9640.  
  9641.         move.b    (a0),d1
  9642.         btst    #0,d0
  9643.         bne.b    bit0
  9644.         btst    #6,d1
  9645.         bne.b    bit6
  9646.         bset    #7,d1
  9647.         bra.b    go7
  9648.  
  9649. bit0:        bclr    #7,d1
  9650. go7:        move.b    d1,(a0)
  9651. bit6:        rts
  9652.  
  9653. **************************************************************************
  9654. **************************************************************************
  9655.  
  9656. ;----------------------------------------------------------
  9657.  
  9658. NODISK_ERR        equ 1
  9659. TRACKCORRUPT_ERR    equ 2
  9660. BADCHECKSUM_ERR        equ 3
  9661. NOTDOS_ERR        equ 4
  9662. WRITEPROTECT_ERR    equ 5
  9663. CREATEFILE_ERR        equ 6
  9664. FILENOTFOUND_ERR    equ 7
  9665. DISKFULL_ERR        equ 8
  9666. FILEEXIST_ERR        equ 9
  9667. DEVICENOTFOUND_ERR    equ 10
  9668. ILLEGALPATH_ERR        equ 11
  9669. NOFFS_ERR        equ 12
  9670. IDE_ERR            equ 13
  9671. NOTEMPTY_ERR        equ 14
  9672.  
  9673.         STRUCTURE partition,0
  9674.         ULONG part_next        ;ptr on next partition
  9675.         ULONG part_first    ;first sector of this partition
  9676.         ULONG part_nbsec    ;nb sectors in this partition
  9677.         ULONG part_device    ;ptr on device
  9678.         UWORD part_unit        ;unit number
  9679.         ULONG part_filesystem    ;filesystem ID (DOS\0,....) 0=nodisk
  9680.         STRUCT part_name,32    ;partition_name (BCPL) (upper case)
  9681.         STRUCT part_name2,32    ;partition_name (BCPL) (original case)
  9682.         LABEL part_SIZEOF
  9683.  
  9684.         STRUCTURE file_handle,0
  9685.         ULONG file_part        ;ptr on partition
  9686.         ULONG file_parent    ;parent
  9687.         ULONG file_header
  9688.         ULONG file_extension
  9689.         ULONG file_extpos
  9690.         ULONG file_size
  9691.         ULONG file_seek
  9692.         STRUCT file_name,32    ;1st byte=len of name (max 30) (BCPL)
  9693.         UBYTE file_written
  9694.         UBYTE file_dir        ;0=it is a file, -1 it is a dir
  9695.                     ;(used by ExNext only)
  9696.         LABEL file_SIZEOF
  9697.  
  9698.  
  9699. ;-------------- device is accesed by open,read,write,close,seek... cmd ------
  9700.  
  9701. READ_CMD equ 0
  9702. WRITE_CMD equ 4
  9703. UPDATE_CMD equ 8
  9704. MOTOFF_CMD equ 12
  9705. CHANGE_CMD equ 16
  9706. READM_CMD equ 20
  9707. WRITEM_CMD equ 24
  9708.  
  9709.     OPT_OFF
  9710. floppy_device    bra.w    floppy_read
  9711.         bra.w    floppy_write
  9712.         bra.w    floppy_update
  9713.         bra.w    floppy_motoff
  9714.         bra.w    floppy_change
  9715.         bra.w    floppy_readm
  9716.         bra.w    floppy_writem
  9717.     OPT_ON
  9718.  
  9719. ;-> a3=ptr on part
  9720. ;-> d0=no of first block to read
  9721. ;-> d1=nb of block to read
  9722. ;-> on stack=ptr on blocks
  9723.  
  9724. floppy_readm    movem.l    d0-d1/a0/a4,-(a7)
  9725.         lea.l    4+4*4(a7,d1.w*4),a4
  9726.         bra.b    .godbf
  9727. .loop        move.l    -(a4),a0
  9728.         bsr    floppy_read
  9729.         addq.l    #1,d0
  9730. .godbf        dbf    d1,.loop
  9731.         movem.l    (a7)+,d0-d1/a0/a4
  9732.         move.l    (a7),(a7,d1.w*4)
  9733.         lea.l    (a7,d1.w*4),a7
  9734.         rts
  9735.  
  9736. ;-> a3=ptr on part
  9737. ;-> d0=no of first block to write
  9738. ;-> d1=nb of block to write
  9739. ;-> on stack=ptr on blocks
  9740.  
  9741. floppy_writem    movem.l    d0-d1/a0/a4,-(a7)
  9742.         lea.l    4+4*4(a7,d1.w*4),a4
  9743.         bra.b    .godbf
  9744. .loop        move.l    -(a4),a0
  9745.         bsr    floppy_write
  9746.         addq.l    #1,d0
  9747. .godbf        dbf    d1,.loop
  9748.         movem.l    (a7)+,d0-d1/a0/a4
  9749.         move.l    (a7),(a7,d1.w*4)
  9750.         lea.l    (a7,d1.w*4),a7
  9751.         rts
  9752.  
  9753. ;-> a3=ptr on part
  9754. ;-> d0=no of block to read
  9755. ;-> a0=buffer ptr
  9756.  
  9757. floppy_read    move.l    d0,-(a7)
  9758.         add.l    part_first(a3),d0
  9759.         cmp.w    #0,part_unit(a3)        ;DF0 ?
  9760.         bne.b    .no0
  9761.         cmp.w    #3,drive
  9762.         beq.b    .read
  9763.         bsr    write_flush
  9764.         move.w    #3,drive
  9765.         move.l    d0,-(a7)
  9766.         moveq    #1,d0                ;force floppy change
  9767.         bsr    floppy_change
  9768.         move.l    (a7)+,d0
  9769.         bra.b    .read
  9770.  
  9771. .no0        cmp.w    #1,part_unit(a3)        ;DF1 ?
  9772.         bne.b    .no1
  9773.         cmp.w    #4,drive
  9774.         beq.b    .read
  9775.         bsr    write_flush
  9776.         move.w    #4,drive
  9777.         move.l    d0,-(a7)
  9778.         moveq    #1,d0                ;force floppy change
  9779.         bsr    floppy_change
  9780.         move.l    (a7)+,d0
  9781.         bra.b    .read
  9782. .no1        bra.b    .err
  9783.  
  9784. .read        bsr    read_fsector
  9785. .err        move.l    (a7)+,d0
  9786.         rts
  9787.  
  9788. ;-> a3=ptr on part
  9789. ;-> d0=no of block to write
  9790. ;-> a0=buffer ptr
  9791.  
  9792. floppy_write    move.l    d0,-(a7)
  9793.  
  9794.         bsr    signal_write
  9795.  
  9796.         add.l    part_first(a3),d0
  9797.         cmp.w    #0,part_unit(a3)        ;DF0 ?
  9798.         bne.b    .no0
  9799.         cmp.w    #3,drive
  9800.         beq.b    .write
  9801.         bsr    write_flush
  9802.         move.w    #3,drive
  9803.         move.l    d0,-(a7)
  9804.         moveq    #1,d0                ;force floppy change
  9805.         bsr    floppy_change
  9806.         move.l    (a7)+,d0
  9807.         bra.b    .write
  9808.  
  9809. .no0        cmp.w    #1,part_unit(a3)        ;DF1 ?
  9810.         bne.b    .no1
  9811.         cmp.w    #4,drive
  9812.         beq.b    .write
  9813.         bsr    write_flush
  9814.         move.w    #4,drive
  9815.         move.l    d0,-(a7)
  9816.         moveq    #1,d0                ;force floppy change
  9817.         bsr    floppy_change
  9818.         move.l    (a7)+,d0
  9819.         bra.b    .write
  9820. .no1        bra.b    .err
  9821.  
  9822. .write        bsr    write_fsector
  9823. .err        move.l    (a7)+,d0
  9824.         rts
  9825.  
  9826. ;-> a3=ptr on part
  9827.  
  9828. floppy_update    bsr    write_flush
  9829.         rts
  9830.  
  9831. ;-> a3=ptr on part
  9832.  
  9833. floppy_motoff    cmp.w    #0,part_unit(a3)        ;DF0 ?
  9834.         bne.b    .no0
  9835.         cmp.w    #3,drive
  9836.         beq.b    .motoff
  9837.         bsr    write_flush
  9838.         move.w    #3,drive
  9839.         move.l    d0,-(a7)
  9840.         moveq    #1,d0                ;force floppy change
  9841.         bsr    floppy_change
  9842.         move.l    (a7)+,d0
  9843.         bra.b    .motoff
  9844.  
  9845. .no0        cmp.w    #1,part_unit(a3)        ;DF1 ?
  9846.         bne.b    .no1
  9847.         cmp.w    #4,drive
  9848.         beq.b    .motoff
  9849.         bsr    write_flush
  9850.         move.w    #4,drive
  9851.         move.l    d0,-(a7)
  9852.         moveq    #1,d0                ;force floppy change
  9853.         bsr    floppy_change
  9854.         move.l    (a7)+,d0
  9855.         bra.b    .motoff
  9856. .no1        bra.b    .err
  9857.  
  9858. .motoff        bsr    motor_off
  9859. .err        rts
  9860.  
  9861. ;-> a3=ptr on part
  9862. ;-> d0=cmd 0=test if changed 1=force change
  9863. ;<- d0 0=nochange -1=nodisk 1=newdisk
  9864.  
  9865. floppy_change    movem.l    a0,-(a7)
  9866.         tst.l    d0
  9867.         bne.w    .force
  9868.         cmp.w    #0,part_unit(a3)        ;DF0 ?
  9869.         bne.b    .no0
  9870.         cmp.w    #3,drive
  9871.         beq.w    .gochg
  9872.         bsr    write_flush
  9873.         move.w    #3,drive
  9874.         movem.l    d0/a0,-(a7)
  9875.         lea.l    track_sector,a0
  9876.         moveq    #-1,d0
  9877.         move.l    d0,(a0)+
  9878.         move.l    d0,(a0)+
  9879.         move.l    d0,(a0)+
  9880.         move.w    d0,track_buffer_no
  9881.         movem.l    (a7)+,d0/a0
  9882.         bra.b    .gochg
  9883.  
  9884. .no0        cmp.w    #1,part_unit(a3)        ;DF1 ?
  9885.         bne.b    .no1
  9886.         cmp.w    #4,drive
  9887.         beq.b    .gochg
  9888.         bsr    write_flush
  9889.         move.w    #4,drive
  9890.         movem.l    d0/a0,-(a7)
  9891.         lea.l    track_sector,a0
  9892.         moveq    #-1,d0
  9893.         move.l    d0,(a0)+
  9894.         move.l    d0,(a0)+
  9895.         move.l    d0,(a0)+
  9896.         move.w    d0,track_buffer_no
  9897.         movem.l    (a7)+,d0/a0
  9898.         bra.b    .gochg
  9899.  
  9900. .no1        bra.w    .err
  9901.  
  9902. .force        lea.l    track_sector,a0
  9903.         moveq    #-1,d0
  9904.         move.l    d0,(a0)+
  9905.         move.l    d0,(a0)+
  9906.         move.l    d0,(a0)+
  9907.         move.w    d0,track_buffer_no
  9908.         moveq    #1,d0            ;new disk
  9909.         bra.b    .out
  9910.  
  9911. .gochg        lea.l    $bfd100,a0
  9912.         move.w    drive,d0
  9913.         bclr    d0,(a0)            ;select drive
  9914.         bclr    #1,(a0)            ;step dir -> 80
  9915.         bsr    timer1
  9916.         btst    #2,$bfe001        ;/CHNG ?
  9917.         bne.b    .nochg
  9918.  
  9919.         bsr    step_head
  9920.         bset    #1,(a0)            ;step dir -> 00
  9921.         bsr    timer1
  9922.         bsr    step_head
  9923.         bsr    timer1
  9924.         btst    #2,$bfe001
  9925.         bne.b    .newdisk
  9926.         bset    d0,(a0)            ;deselect drive
  9927.         move.w    #NODISK_ERR,drive_err
  9928.         moveq    #-1,d0            ;no disk
  9929.         bra.b    .out
  9930.  
  9931. .newdisk    bset    d0,(a0)            ;deselect drive
  9932.         lea.l    track_sector,a0
  9933.         moveq    #-1,d0
  9934.         move.l    d0,(a0)+
  9935.         move.l    d0,(a0)+
  9936.         move.l    d0,(a0)+
  9937.         move.w    d0,track_buffer_no
  9938.         moveq    #1,d0            ;new disk
  9939.         bra.b    .out
  9940.  
  9941. .nochg        bset    d0,(a0)            ;deselect drive
  9942.         moveq    #0,d0            ;no change
  9943.         bra.b    .out
  9944.  
  9945. .err        moveq    #1,d0
  9946. .out        movem.l    (a7)+,a0
  9947.         rts
  9948.  
  9949.  
  9950.     OPT_OFF
  9951. ide_device    bra.w    ide_read
  9952.         bra.w    ide_write
  9953.         bra.w    ide_update
  9954.         bra.w    ide_motoff
  9955.         bra.w    ide_change
  9956.         bra.w    ide_readm
  9957.         bra.w    ide_writem
  9958.     OPT_ON
  9959.  
  9960. ;-> a3=ptr on part
  9961. ;-> d0=no of first block to read
  9962. ;-> d1=nb of block to read
  9963. ;-> on stack=ptr on blocks
  9964.  
  9965. ide_readm    movem.l    d0-d1/a0/a4,-(a7)
  9966.         lea.l    4+4*4(a7,d1.w*4),a4
  9967.         bra.b    .godbf
  9968. .loop        move.l    -(a4),a0
  9969.         bsr    ide_read
  9970.         addq.l    #1,d0
  9971. .godbf        dbf    d1,.loop
  9972.         movem.l    (a7)+,d0-d1/a0/a4
  9973.         move.l    (a7),(a7,d1.w*4)
  9974.         lea.l    (a7,d1.w*4),a7
  9975.         rts
  9976.  
  9977. ;-> a3=ptr on part
  9978. ;-> d0=no of first block to write
  9979. ;-> d1=nb of block to write
  9980. ;-> on stack=ptr on blocks
  9981.  
  9982.  
  9983. ide_writem    movem.l    d0-d2/a0,-(a7)
  9984.  
  9985.         bsr    signal_write
  9986.  
  9987.         add.l    part_first(a3),d0
  9988.  
  9989.         lea.l    4+4*4(a7,d1.w*4),a0
  9990.  
  9991.         move.w    d1,d2
  9992.         move.w    part_unit(a3),d1
  9993.         bsr    WriteM_Block
  9994.  
  9995.         tst.l    d0
  9996.         beq.b    .noerr
  9997. .err        move.w    #IDE_ERR,drive_err
  9998. .noerr
  9999.         movem.l    (a7)+,d0-d2/a0
  10000.         move.l    (a7),(a7,d1.w*4)
  10001.         lea.l    (a7,d1.w*4),a7
  10002.         rts
  10003.  
  10004. ;-> a3 = part
  10005.  
  10006. signal_write    movem.l    d2/a0/a3,-(a7)
  10007.         lea.l    changed_disk,a0
  10008.         moveq    #16-1,d2
  10009. .seek        cmp.l    (a0)+,a3
  10010.         beq.b    .found
  10011.         dbf    d2,.seek
  10012.  
  10013.         lea.l    changed_disk,a0
  10014. .seek2        tst.l    (a0)+
  10015.         bne.b    .seek2
  10016.         move.l    a3,-4(a0)
  10017.  
  10018. .found        movem.l    (a7)+,d2/a0/a3
  10019.         rts
  10020.  
  10021.  
  10022. ;-> d0=block no
  10023. ;-> a0=address
  10024. ;-> a3=part
  10025.  
  10026. ide_read    movem.l    d0-d1,-(a7)
  10027.         cmp.l    part_nbsec(a3),d0
  10028.         bge.b    .err
  10029.         add.l    part_first(a3),d0
  10030.         move.w    part_unit(a3),d1
  10031.         bsr    Read_Block
  10032.         tst.l    d0
  10033.         beq.b    .noerr
  10034. .err        move.w    #IDE_ERR,drive_err
  10035. .noerr        movem.l    (a7)+,d0-d1
  10036.         rts
  10037.  
  10038. ;-> d0=block no
  10039. ;-> a0=address
  10040. ;-> a3=part
  10041.  
  10042. ide_write    movem.l    d0-d1,-(a7)
  10043.  
  10044.         bsr    signal_write
  10045.  
  10046.         cmp.l    part_nbsec(a3),d0
  10047.         bge.b    .err
  10048.         add.l    part_first(a3),d0
  10049.         move.w    part_unit(a3),d1
  10050.         bsr    Write_Block
  10051.         tst.l    d0
  10052.         beq.b    .noerr
  10053. .err        move.w    #IDE_ERR,drive_err
  10054. .noerr        movem.l    (a7)+,d0-d1
  10055.         rts
  10056.  
  10057. ide_update    rts
  10058. ide_motoff    rts
  10059. ide_change    moveq    #0,d0        ;no change
  10060.         rts
  10061.  
  10062. ;-------------- find the partitions on the HardDisks ------
  10063.  
  10064. find_part    movem.l    d0-a4,-(a7)
  10065.  
  10066.         lea.l    floppy0,a1
  10067. .seekend    move.l    (a1),d1
  10068.         beq.b    .endoflist
  10069.         move.l    d1,a1
  10070.         bra.b    .seekend
  10071.  
  10072. .endoflist    lea.l    secbuf,a0
  10073.         moveq    #0,d1
  10074.         bsr    Read_ID
  10075.         tst.l    d0
  10076.         bne.b    .nodrive0
  10077.         bsr    .search_part
  10078. .nodrive0
  10079.         tst.b    config_elsat
  10080.         bne.b    .nodrive1
  10081.         lea.l    secbuf,a0
  10082.         moveq    #1,d1
  10083.         bsr    Read_ID
  10084.         tst.l    d0
  10085.         bne.b    .nodrive1
  10086.         bsr    .search_part
  10087. .nodrive1
  10088.         lea.l    secbuf,a0
  10089.         moveq    #0,d1
  10090.         moveq    #0,d0
  10091.         tst.w    IDE_info0
  10092.         beq.b    .no0
  10093.         bsr    Read_Block
  10094. .no0
  10095.         movem.l    (a7)+,d0-a4
  10096.         rts
  10097.  
  10098. ;-------------- search partitions in rigid disk blocks ----
  10099.  
  10100. ;-> d1=drive no (unit)
  10101. ;-> a1=last partition
  10102.  
  10103. .search_part
  10104.         moveq    #0,d6
  10105. .seek        lea.l    secbuf,a0
  10106.         move.l    d6,d0
  10107.         bsr    Read_Block    ;read first RDSK
  10108.         cmp.l    #"RDSK",(a0)
  10109.         beq.b    .okrdsk
  10110.         addq.l    #1,d6
  10111.         cmp.l    #RDB_LOCATION_LIMIT,d6
  10112.         beq.w    .error
  10113.         bra.b    .seek
  10114. .okrdsk        move.l    rdb_Sectors(a0),d6
  10115.         move.l    rdb_Heads(a0),d0
  10116.         mulu    d0,d6        ;d6=nbsectors/cyl
  10117.         move.l    rdb_PartitionList(a0),d0
  10118.         beq.w    .error
  10119. .read_next    moveq    #-1,d2
  10120.         cmp.l    d2,d0        ;end of list ?
  10121.         beq.w    .error
  10122.         bsr    Read_Block    ;read PART
  10123.         cmp.l    #"PART",(a0)
  10124.         bne.w    .error
  10125.         move.l    192(a0),d0
  10126.         lsr.l    #8,d0
  10127.         cmp.l    #"DOS",d0    ;Amiga DOS filesystem ?
  10128.         bne.w    .next
  10129.  
  10130.         lea.l    part_SIZEOF(a1),a2
  10131.         cmp.l    #harddisk_end,a2    ;max nb of part reached ?
  10132.         bge.w    .error
  10133.  
  10134.         move.l    a2,part_next(a1)
  10135.         move.l    a2,a1
  10136.         clr.l    part_next(a1)
  10137.  
  10138.         lea.l    pb_DriveName(a0),a2
  10139.         lea.l    part_name(a1),a3
  10140.         lea.l    part_name2(a1),a4
  10141.         clr.l    (a3)        ;clear DF1: name if needed
  10142.         moveq    #0,d2
  10143.         move.b    (a2)+,d2
  10144.         move.b    d2,(a3)+    ;copy name length
  10145.         move.b    d2,(a4)+
  10146.         bra.b    .godbf2
  10147. .copyn        move.b    (a2)+,d0
  10148.         move.b    d0,(a4)+
  10149.         bsr    upper_case
  10150.         move.b    d0,(a3)+    ;copy Partition name
  10151. .godbf2        dbf    d2,.copyn
  10152.  
  10153.         move.l    $a4(a0),d0    ;First cylinder
  10154.         mulu    d6,d0        ;d0=first sector
  10155.         move.l    d0,part_first(a1)
  10156.         move.l    $a8(a0),d2    ;last cylinder
  10157.         addq.w    #1,d2
  10158.         mulu    d6,d2        ;last sector+1
  10159.         sub.l    d0,d2
  10160.         move.l    d2,part_nbsec(a1)
  10161.         move.w    d1,part_unit(a1)
  10162.  
  10163.         move.l    #ide_device,part_device(a1)
  10164.  
  10165.         lea.l    extension,a0
  10166.         bsr    Read_Block    ;Read first sector
  10167.         move.l    (a0),part_filesystem(a1)
  10168.         lea.l    secbuf,a0
  10169.  
  10170. .next        move.l    pb_Next(a0),d0
  10171.         bne.w    .read_next
  10172.  
  10173. .error        rts
  10174.  
  10175. ;----------------------------------------------------------
  10176.  
  10177. ide_base    dc.l 0        ;$da2000 / $dd2020 / $EB8000 (A1200,A4000,CD32elsat)
  10178. ide_irq        dc.l 0        ;$da9000 / $dd3020 / $0
  10179.  
  10180. ide_data    dc.w 0
  10181. ide_error    dc.w 0
  10182. ide_feature    dc.w 0
  10183. ide_secnt    dc.w 0
  10184. ide_secnb    dc.w 0
  10185. ide_cyllo    dc.w 0
  10186. ide_cylhi    dc.w 0
  10187. ide_dhead    dc.w 0
  10188. ide_status    dc.w 0
  10189. ide_command    dc.w 0
  10190. ide_altstat    dc.w 0
  10191.  
  10192. ;$da8000+$1000 interrupt register
  10193.  
  10194. ;-> a0=ID_Buffer
  10195. ;-> d1=drive no (0/1)
  10196. ;<- d0=error 0=ok -1=an error occured (No Drive)
  10197.  
  10198. Read_ID        movem.l    d1-d2/a0-a1/a3,-(a7)
  10199.         lea.l    IDE_info0,a1
  10200.         tst.w    d1
  10201.         beq.b    .okdrive0
  10202.         lea.l    IDE_info1,a1
  10203. .okdrive0
  10204.         move.l    ide_base(pc),a3
  10205.  
  10206.         move.b    #0,$bfe801
  10207. .wait        cmp.b    #80,$bfe801
  10208.         bhi.w    .error
  10209.         move.w    ide_status,d0
  10210.         tst.b    (a3,d0.w)
  10211.         bmi.b    .wait            ;BUSY ?
  10212.  
  10213.         lsl.b    #4,d1
  10214.         and.b    #$10,d1            ;Drive bit
  10215.         or.b    #$a0,d1
  10216.         move.w    ide_dhead,d0
  10217.         move.b    d1,(a3,d0.w)
  10218.         move.w    ide_command,d0
  10219.         move.b    #$EC,(a3,d0.w)        ;Identify Drive cmd
  10220.  
  10221.         bsr    wait_irq2
  10222.         bne.b    .error
  10223.  
  10224.         move.w    ide_status,d0
  10225.         move.b    (a3,d0.w),d0
  10226.         btst    #0,d0
  10227.         bne.b    .error
  10228.  
  10229.         movem.l    a0/a1,-(a7)
  10230.         move.w    ide_data,d0
  10231.         lea.l    (a3,d0.w),a1
  10232.         move.w    #512/2-1,d0
  10233. .copy        move.w    (a1),d1
  10234.         ror.w    #8,d1            ;LittleEndian to BigEndian
  10235.         move.w    d1,(a0)+
  10236.         dbf    d0,.copy
  10237.         movem.l    (a7)+,a0/a1
  10238.  
  10239.         move.w    1*2(a0),II_NbCyl(a1)
  10240.         move.w    3*2(a0),II_NbHeads(a1)
  10241.         move.w    6*2(a0),II_NbSecTrack(a1)
  10242.         moveq    #0,d1
  10243.         move.w    59*2(a0),d0
  10244.         btst    #8,d0            ;setting valid ?
  10245.         beq.b    .nomult
  10246.         move.b    d0,d1
  10247. .nomult        move.w    d1,II_MultSize(a1)
  10248.  
  10249.         move.w    ide_status,d0
  10250.         move.b    (a3,d0.w),d0
  10251.         btst    #0,d0
  10252.         bne.b    .error
  10253.         moveq    #0,d0
  10254.         bra.b    .out
  10255. .error        moveq    #-1,d0
  10256. .out        movem.l    (a7)+,d1-d2/a0-a1/a3
  10257.         rts
  10258.  
  10259. ;-> a3=ide_base
  10260. wait_irq    movem.l    d0/a0,-(a7)
  10261.         move.w    #8,$dff09a        ;disable CIA IRQ
  10262.         tst.l    ide_irq
  10263.         bne.b    .nocd32
  10264.         move.w    ide_altstat,d0
  10265. .busy        tst.b    (a3,d0.w)
  10266.         bmi.b    .busy
  10267.         move.w    ide_status,d0
  10268.         move.b    (a3,d0.w),d0        ;ack int
  10269.         bra.b    .ok
  10270. .nocd32        tst.b    IDE_IRQ            ;already got IRQ ?
  10271.         bne.b    .ok
  10272. .noirq        move.l    ide_irq(pc),a0
  10273.         move.b    (a0),d0
  10274.         bpl.b    .noirq
  10275.         tst.b    config_A1200
  10276.         bne.b    .go1200
  10277.         move.w    ide_status,d0
  10278.         move.b    (a3,d0.w),d0
  10279.         bra.b    .ok
  10280. .go1200        move.w    SR,-(a7)
  10281.         move.w    #$2700,sr
  10282.         move.w    ide_status,d0
  10283.         move.b    (a3,d0.w),d0
  10284.         move.b    (a0),d0
  10285.         andi.b    #3,d0
  10286.         or.b    #$7c,d0
  10287.         move.b    d0,(a0)
  10288.         move.w    (a7)+,SR
  10289. .ok        sf    IDE_IRQ
  10290.         move.w    #$8008,$dff09a        ;enable CIA IRQ
  10291.         movem.l    (a7)+,d0/a0
  10292.         rts
  10293.  
  10294.  
  10295. ;same as wait_irq but doesn't wait more than 80 ticks
  10296. ;-> a3=ide_base
  10297. ;<- Z flag RESULT unset=ERROR set=OK
  10298.  
  10299. wait_irq2    movem.l    d0/a0,-(a7)
  10300.  
  10301.         move.w    #8,$dff09a        ;disable CIA IRQ
  10302.         tst.l    ide_irq
  10303.         bne.b    .nocd32
  10304.         move.b    #0,$bfe801
  10305. .loop        cmp.b    #80,$bfe801
  10306.         bhi.w    .err
  10307.         move.w    ide_altstat,d0
  10308.         move.b    (a3,d0.w),d0
  10309.         bpl.b    .ok2
  10310.         bra.b    .loop
  10311. .ok2        move.w    ide_status,d0
  10312.         move.b    (a3,d0.w),d0        ;ack int
  10313.         btst    #0,d0
  10314.         bne.w    .err
  10315.         jmp    .ok
  10316.  
  10317. .nocd32        tst.b    IDE_IRQ            ;already got IRQ ?
  10318.         bne.b    .ok
  10319.         move.b    #0,$bfe801
  10320. .noirq        cmp.b    #80,$bfe801
  10321.         bhi.b    .err
  10322.         move.l    ide_irq(pc),a0
  10323.         move.b    (a0),d0
  10324.         bpl.b    .noirq
  10325.         tst.b    config_A1200
  10326.         bne.b    .go1200
  10327.         move.w    ide_status,d0
  10328.         move.b    (a3,d0.w),d0
  10329.         bra.b    .ok
  10330. .go1200        move.w    SR,-(a7)
  10331.         move.w    #$2700,sr
  10332.         move.w    ide_status,d0
  10333.         move.b    (a3,d0.w),d0
  10334.         move.b    (a0),d0
  10335.         andi.b    #3,d0
  10336.         or.b    #$7c,d0
  10337.         move.b    d0,(a0)
  10338.         move.w    (a7)+,SR
  10339. .ok        sf    IDE_IRQ
  10340.         move.w    #$8008,$dff09a        ;enable CIA IRQ
  10341.         moveq    #0,d0
  10342.         movem.l    (a7)+,d0/a0
  10343.         rts
  10344.  
  10345. .err        move.w    #$8008,$dff09a        ;enable CIA IRQ
  10346.         moveq    #-1,d0
  10347.         movem.l    (a7)+,d0/a0
  10348.         rts
  10349.  
  10350.  
  10351. ;-> d0=block no
  10352. ;-> d1=drive no (0/1)
  10353. ;-> a0=dest address
  10354.  
  10355. Read_Block    movem.l    d1-d2/a0-a1/a3,-(a7)
  10356.  
  10357.         lea.l    IDE_info0,a1
  10358.         tst.w    d1
  10359.         beq.b    .okdrive0
  10360.         lea.l    IDE_info1,a1
  10361. .okdrive0
  10362.         tst.w    (a1)            ;drive exists ?
  10363.         beq.w    .error
  10364.  
  10365.         move.l    ide_base(pc),a3
  10366.  
  10367. .wait        move.w    ide_status,d2
  10368.         tst.b    (a3,d2.w)
  10369.         bmi.b    .wait            ;BUSY ?
  10370.  
  10371.         lsl.b    #4,d1
  10372.         and.b    #$10,d1            ;Drive bit
  10373.         or.b    #$a0,d1
  10374.  
  10375.         move.w    II_NbHeads(a1),d2    ;nb_heads
  10376.         mulu    II_NbSecTrack(a1),d2    ;*nb_sectrack d2=nb sec/cyl
  10377.         tst.w    d2
  10378.         beq.w    .error
  10379.         divu    d2,d0            ;d0=cyl no.
  10380.         cmp.w    II_NbCyl(a1),d0        ;nb_cyl
  10381.         bge.w    .error
  10382.  
  10383.         move.w    ide_cyllo,d2
  10384.         move.b    d0,(a3,d2.w)
  10385.         lsr.w    #8,d0
  10386.         move.w    ide_cylhi,d2
  10387.         move.b    d0,(a3,d2.w)
  10388.         clr.w    d0
  10389.         swap    d0
  10390.         divu    II_NbSecTrack(a1),d0    ;/nb_sectrack d0=no of head
  10391.         and.w    #%1111,d0
  10392.         or.b    d0,d1
  10393.         swap    d0
  10394.         cmp.w    II_NbSecTrack(a1),d0    ;nb_sectrack
  10395.         bge.w    .error
  10396.         addq.b    #1,d0
  10397.         move.w    ide_secnb,d2
  10398.         move.b    d0,(a3,d2.w)        ;start sector
  10399.  
  10400.         move.w    ide_dhead,d2
  10401.         move.b    d1,(a3,d2.w)
  10402.         move.w    ide_secnt,d2
  10403.         move.b    #1,(a3,d2.w)        ;read 1 sector
  10404.  
  10405.         move.w    ide_command,d2
  10406.         move.b    #$20,(a3,d2.w)        ;Read Drive cmd
  10407.  
  10408.         bsr    wait_irq
  10409.  
  10410.         move.w    ide_status,d0
  10411.         move.b    (a3,d0.w),d0
  10412.         btst    #0,d0
  10413.         bne.b    .error
  10414.  
  10415.         move.w    ide_data,d0
  10416.         lea.l    (a3,d0.w),a1
  10417.         move.w    #512/32-1,d0
  10418. .read        move.w    (a1),(a0)+
  10419.         move.w    (a1),(a0)+
  10420.         move.w    (a1),(a0)+
  10421.         move.w    (a1),(a0)+
  10422.         move.w    (a1),(a0)+
  10423.         move.w    (a1),(a0)+
  10424.         move.w    (a1),(a0)+
  10425.         move.w    (a1),(a0)+
  10426.         move.w    (a1),(a0)+
  10427.         move.w    (a1),(a0)+
  10428.         move.w    (a1),(a0)+
  10429.         move.w    (a1),(a0)+
  10430.         move.w    (a1),(a0)+
  10431.         move.w    (a1),(a0)+
  10432.         move.w    (a1),(a0)+
  10433.         move.w    (a1),(a0)+
  10434.         dbf    d0,.read
  10435.  
  10436.         move.w    ide_status,d0
  10437.         move.b    (a3,d0.w),d0
  10438.         btst    #0,d0
  10439.         bne.b    .error
  10440.         moveq    #0,d0
  10441.         bra.b    .out
  10442. .error        moveq    #-1,d0
  10443. .out        movem.l    (a7)+,d1-d2/a0-a1/a3
  10444.         rts
  10445.  
  10446.  
  10447. ;-> d0=block no
  10448. ;-> d1=drive no (0/1)
  10449. ;-> a0=source address
  10450.  
  10451. Write_Block    movem.l    d1-d2/a0-a1/a3,-(a7)
  10452.  
  10453.         lea.l    IDE_info0,a1
  10454.         tst.w    d1
  10455.         beq.b    .okdrive0
  10456.         lea.l    IDE_info1,a1
  10457. .okdrive0
  10458.         tst.w    (a1)            ;drive exists ?
  10459.         beq.w    .error
  10460.  
  10461.         move.l    ide_base(pc),a3
  10462.  
  10463. .wait        move.w    ide_status,d2
  10464.         tst.b    (a3,d2.w)
  10465.         bmi.b    .wait            ;BUSY ?
  10466.  
  10467.         lsl.b    #4,d1
  10468.         and.b    #$10,d1            ;Drive bit
  10469.         or.b    #$a0,d1
  10470.  
  10471.         move.w    II_NbHeads(a1),d2    ;nb_heads
  10472.         mulu    II_NbSecTrack(a1),d2    ;*nb_sectrack d2=nb sec/cyl
  10473.         divu    d2,d0            ;d0=cyl no.
  10474.         tst.w    d2
  10475.         beq.w    .error
  10476.         cmp.w    II_NbCyl(a1),d0        ;nb_cyl
  10477.         bge.w    .error
  10478.  
  10479.         move.w    ide_cyllo,d2
  10480.         move.b    d0,(a3,d2.w)
  10481.         lsr.w    #8,d0
  10482.         move.w    ide_cylhi,d2
  10483.         move.b    d0,(a3,d2.w)
  10484.         clr.w    d0
  10485.         swap    d0
  10486.         divu    II_NbSecTrack(a1),d0    ;/nb_sectrack d0=no of head
  10487.         and.w    #%1111,d0
  10488.         or.b    d0,d1
  10489.         swap    d0
  10490.         cmp.w    II_NbSecTrack(a1),d0    ;nb_sectrack
  10491.         bge.w    .error
  10492.         addq.b    #1,d0
  10493.         move.w    ide_secnb,d2
  10494.         move.b    d0,(a3,d2.w)        ;start sector
  10495.  
  10496.         move.w    ide_dhead,d2
  10497.         move.b    d1,(a3,d2.w)
  10498.         move.w    ide_secnt,d2
  10499.         move.b    #1,(a3,d2.w)        ;read 1 sector
  10500.  
  10501.         move.w    ide_command,d2
  10502.         move.b    #$30,(a3,d2.w)        ;Write Drive cmd
  10503.  
  10504. .busy        move.w    ide_status,d0
  10505.         move.b    (a3,d0.w),d0
  10506.         bmi.b    .busy
  10507.         btst    #0,d0
  10508.         bne.b    .error
  10509.         btst    #3,d0            ;DRQ ?
  10510.         beq.b    .busy
  10511.  
  10512.         move.w    ide_data,d0
  10513.         lea.l    (a3,d0.w),a1
  10514.         move.w    #512/32-1,d0
  10515. .write        move.w    (a0)+,(a1)
  10516.         move.w    (a0)+,(a1)
  10517.         move.w    (a0)+,(a1)
  10518.         move.w    (a0)+,(a1)
  10519.         move.w    (a0)+,(a1)
  10520.         move.w    (a0)+,(a1)
  10521.         move.w    (a0)+,(a1)
  10522.         move.w    (a0)+,(a1)
  10523.         move.w    (a0)+,(a1)
  10524.         move.w    (a0)+,(a1)
  10525.         move.w    (a0)+,(a1)
  10526.         move.w    (a0)+,(a1)
  10527.         move.w    (a0)+,(a1)
  10528.         move.w    (a0)+,(a1)
  10529.         move.w    (a0)+,(a1)
  10530.         move.w    (a0)+,(a1)
  10531.         dbf    d0,.write
  10532.  
  10533.         bsr    wait_irq
  10534.  
  10535. .busy2        move.w    ide_status,d0
  10536.         move.b    (a3,d0.w),d0
  10537.         btst    #0,d0
  10538.         bne.b    .error
  10539.         btst    #7,d0
  10540.         bne.b    .busy2
  10541.         moveq    #0,d0
  10542.         bra.b    .out
  10543. .error        moveq    #-1,d0
  10544. .out        movem.l    (a7)+,d1-d2/a0-a1/a3
  10545.         rts
  10546.  
  10547. ;-> d0=block no
  10548. ;-> d1=drive no (0/1)
  10549. ;-> d2=nb ok blocks to write
  10550. ;-> a0=ptr on top of stack of source address
  10551.  
  10552.  
  10553. WriteM_Block    movem.l    d1-d3/a0-a3,-(a7)
  10554.  
  10555.         lea.l    IDE_info0,a1
  10556.         tst.w    d1
  10557.         beq.b    .okdrive0
  10558.         lea.l    IDE_info1,a1
  10559. .okdrive0
  10560.         tst.w    d2
  10561.         beq.w    .error
  10562.  
  10563.         tst.w    (a1)            ;drive exists ?
  10564.         beq.w    .error
  10565.  
  10566.         move.l    ide_base(pc),a3
  10567.  
  10568. .wait        move.w    ide_status,d3
  10569.         tst.b    (a3,d3.w)
  10570.         bmi.b    .wait            ;BUSY ?
  10571.  
  10572.         lsl.b    #4,d1
  10573.         and.b    #$10,d1            ;Drive bit
  10574.         or.b    #$a0,d1
  10575.  
  10576.         move.w    II_NbHeads(a1),d3    ;nb_heads
  10577.         mulu    II_NbSecTrack(a1),d3    ;*nb_sectrack d3=nb sec/cyl
  10578.         tst.w    d3
  10579.         beq.w    .error
  10580.         divu    d3,d0            ;d0=cyl no.
  10581.         cmp.w    II_NbCyl(a1),d0        ;nb_cyl
  10582.         bge.w    .error
  10583.  
  10584.         move.w    ide_cyllo,d3
  10585.         move.b    d0,(a3,d3.w)
  10586.         lsr.w    #8,d0
  10587.         move.w    ide_cylhi,d3
  10588.         move.b    d0,(a3,d3.w)
  10589.         clr.w    d0
  10590.         swap    d0
  10591.         divu    II_NbSecTrack(a1),d0    ;/nb_sectrack d0=no of head
  10592.         and.w    #%1111,d0
  10593.         or.b    d0,d1
  10594.         swap    d0
  10595.         cmp.w    II_NbSecTrack(a1),d0    ;nb_sectrack
  10596.         bge.w    .error
  10597.         addq.b    #1,d0
  10598.         move.w    ide_secnb,d3
  10599.         move.b    d0,(a3,d3.w)        ;start sector
  10600.  
  10601.         move.w    ide_dhead,d3
  10602.         move.b    d1,(a3,d3.w)
  10603.  
  10604.         move.w    ide_secnt,d3
  10605.         move.b    d2,(a3,d3.w)        ;write d2 sectors
  10606.  
  10607.         moveq    #$30,d0            ;WriteSector
  10608.         move.w    ide_command,d3
  10609.         move.b    d0,(a3,d3.w)        ;Drive cmd
  10610.  
  10611.         subq.w    #1,d2            ;for dbf
  10612.  
  10613. .busy        move.w    ide_status,d0
  10614.         move.b    (a3,d0.w),d0
  10615.         bmi.b    .busy
  10616.         btst    #0,d0
  10617.         bne.b    .error
  10618.         btst    #3,d0            ;DRQ ?
  10619.         beq.b    .busy
  10620.  
  10621.         move.l    -(a0),a2        ;get next block address
  10622.  
  10623.         move.w    ide_data,d0
  10624.         lea.l    (a3,d0.w),a1
  10625.  
  10626.         move.w    #512/32-1,d0
  10627. .write        move.w    (a2)+,(a1)
  10628.         move.w    (a2)+,(a1)
  10629.         move.w    (a2)+,(a1)
  10630.         move.w    (a2)+,(a1)
  10631.         move.w    (a2)+,(a1)
  10632.         move.w    (a2)+,(a1)
  10633.         move.w    (a2)+,(a1)
  10634.         move.w    (a2)+,(a1)
  10635.         move.w    (a2)+,(a1)
  10636.         move.w    (a2)+,(a1)
  10637.         move.w    (a2)+,(a1)
  10638.         move.w    (a2)+,(a1)
  10639.         move.w    (a2)+,(a1)
  10640.         move.w    (a2)+,(a1)
  10641.         move.w    (a2)+,(a1)
  10642.         move.w    (a2)+,(a1)
  10643.         dbf    d0,.write
  10644.  
  10645.         bsr    wait_irq
  10646.  
  10647.         dbf    d2,.busy
  10648.  
  10649. .busy2        move.w    ide_status,d0
  10650.         move.b    (a3,d0.w),d0
  10651.         btst    #0,d0
  10652.         bne.b    .error
  10653.         btst    #7,d0
  10654.         bne.b    .busy2
  10655.         moveq    #0,d0
  10656.         bra.b    .out
  10657. .error        moveq    #-1,d0
  10658. .out        movem.l    (a7)+,d1-d3/a0-a3
  10659.         rts
  10660.  
  10661. ****************************************************************
  10662.  
  10663.         include src/file.s
  10664.         include src/fbuffers.s
  10665.         include src/cmd_p.s
  10666.         include src/cmd_sp.s
  10667.  
  10668. **************************************************************************
  10669. ;-------------- read the palette from custom registers -------------------
  10670.  
  10671. read_palette    movem.l    d0-d2/a0-a1,-(a7)
  10672.         tst.b    config_AGA
  10673.         beq.b    .noaga
  10674.         move.w    #$0100,$104(a6)        ;set read mode
  10675.         lea.l    paletteL,a0
  10676.         move.w    #$200,d0
  10677.         moveq    #8-1,d1
  10678. .loop_bank    move.w    d0,$106(a6)
  10679.         lea.l    $180(a6),a1
  10680.         moveq    #32-1,d2
  10681. .color        move.w    (a1)+,(a0)+        ;copy bank
  10682.         dbf    d2,.color
  10683.         add.w    #$2000,d0
  10684.         dbf    d1,.loop_bank
  10685.  
  10686.         lea.l    paletteH,a0
  10687.         moveq    #0,d0
  10688.         moveq    #8-1,d1
  10689. .loop_bank2    move.w    d0,$106(a6)
  10690.         lea.l    $180(a6),a1
  10691.         moveq    #32-1,d2
  10692. .color2        move.w    (a1)+,(a0)+        ;copy bank
  10693.         dbf    d2,.color2
  10694.         add.w    #$2000,d0
  10695.         dbf    d1,.loop_bank2
  10696.         move.w    #0,$104(a6)        ;set write mode
  10697. .noaga        movem.l    (a7)+,d0-d2/a0-a1
  10698.         rts
  10699.  
  10700. restore_palette    movem.l    d0-d2/a0-a1,-(a7)
  10701.         tst.b    config_AGA
  10702.         beq.b    .noaga
  10703.  
  10704.         lea.l    paletteH,a0
  10705.         moveq    #0,d0
  10706.         moveq    #8-1,d1
  10707. .loop_bank2    move.w    d0,$106(a6)
  10708.         lea.l    $180(a6),a1
  10709.         moveq    #32-1,d2
  10710. .color2        move.w    (a0)+,(a1)+        ;copy bank
  10711.         dbf    d2,.color2
  10712.         add.w    #$2000,d0
  10713.         dbf    d1,.loop_bank2
  10714.  
  10715.         lea.l    paletteL,a0
  10716.         move.w    #$200,d0
  10717.         moveq    #8-1,d1
  10718. .loop_bank    move.w    d0,$106(a6)
  10719.         lea.l    $180(a6),a1
  10720.         moveq    #32-1,d2
  10721. .color        move.w    (a0)+,(a1)+        ;copy bank
  10722.         dbf    d2,.color
  10723.         add.w    #$2000,d0
  10724.         dbf    d1,.loop_bank
  10725.  
  10726.         move.w    custom+$10c,$10c(a6)    ;for palette EOR
  10727.  
  10728.         move.w    #0,$106(a6)
  10729.  
  10730. .noaga        movem.l    (a7)+,d0-d2/a0-a1
  10731.         rts
  10732.  
  10733.  
  10734. **************************************************************************
  10735. ;-------------- SCAN scan memory for samples -----------------------------
  10736.  
  10737. cmd_scan
  10738.  
  10739.         bra.l    end_command
  10740.  
  10741. **************************************************************************
  10742. *************** MMU routines *********************************************
  10743. **************************************************************************
  10744.  
  10745. ;set a page mode
  10746. ;-> a0 address
  10747. ;-> mode 0=normal, 1=write protected, read/write protected
  10748. ;<- d0 error (0=ok)
  10749.  
  10750.  
  10751. mmu_set_page:
  10752.         cmp.w    #4,proc_type
  10753.         blt.b    .err
  10754.  
  10755. ;-------------- 68040/68060 MMU -----------
  10756.         nop
  10757.  
  10758. .err        moveq    #-1,d0
  10759.         rts
  10760.  
  10761. **************************************************************************
  10762.  
  10763.         include src/disassemble.s
  10764.         include src/assemble.s
  10765.  
  10766. ;make a copy of registers for disassemble function
  10767.  
  10768. init_regBMON    lea.l    regsBMON,a1
  10769.         lea.l    registres,a0
  10770.         moveq    #16-1,d0
  10771. .copy        move.l    (a0)+,(a1)+
  10772.         dbf    d0,.copy
  10773.         move.l    usp_reg,(a1)+
  10774.         move.l    isp_reg,(a1)+
  10775.         move.l    msp_reg,(a1)+
  10776.         move.l    vbr_reg,(a1)+
  10777.         move.l    cacr_reg,(a1)+
  10778.         move.l    caar_reg,(a1)+
  10779.         move.l    pc_reg,(a1)+
  10780.         moveq    #0,d0
  10781.         move.w    sr_reg,d0
  10782.         move.l    d0,(a1)+
  10783.         rts
  10784.  
  10785. ************************************************************
  10786.  
  10787.         include src/keymaps.s
  10788.  
  10789. ;----------------------------------------------------------------------------
  10790.  
  10791. ascII        dc.b "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
  10792.         dc.b "0123456789+",'"'
  10793.         dc.b "*ç%&/()=?'!$#-,;:[]<>@.éàèöäü",$5c,"|§°_¹²{} "
  10794. end_ascII
  10795.  
  10796. ;--- special ascII -------
  10797. ; '¹' = continous line
  10798. ; '²' = small dot
  10799.  
  10800. ;----------------------------------------------------------------------------
  10801.  
  10802. ascIIx        dcb.b $20,"²"
  10803.         dc.b ' !"£$%&',"'()*+,-./0123456789:;<=>?@"
  10804.         dc.b "ABCDEFGHIJKLMNOPQRSTUVWXYZ[",$5c,"]^_²"
  10805.         dc.b "abcdefghijklmnopqrstuvwxyz"
  10806.         dc.b "{|}²çüé²äà²ç²²è"
  10807.         dcb.b 256,"²"
  10808.         even
  10809.  
  10810. hex_list    dc.b "0123456789ABCDEF"
  10811.  
  10812.         cnop 0,4
  10813. ascII_conv    dcb.b 256,0
  10814.  
  10815.  
  10816. file_len_txt    dc.b "File length=$",0
  10817. BP_enter_txt    dc.b "Break Point reached at address $",0
  10818. BPJ_enter_txt    dc.b "JSR Break Point reached at address $",0
  10819. BP_set_txt    dc.b "Break Point set at address $",0
  10820. BPJ_set_txt    dc.b "JSR Break Point set at address $",0
  10821. BP_clr_txt    dc.b "Break Point removed at address $",0
  10822. all_break_txt    dc.b "Break Point at $",0
  10823. all_break2_txt    dc.b "JSR Break Point at $",0
  10824. all_BP_txt    dc.b "All Break Points cleared",$a,0
  10825. show_txt    dc.b "memory address : $",0
  10826. break_txt    dc.b "Break...",$a,0
  10827. drive_txt    dc.b "Active drive is now : ",0
  10828. no_disk_txt    dc.b "No disk in drive ...",$a,0
  10829. corrupt_txt    dc.b "Track corrupted ...",$a,0
  10830. bad_sum_txt    dc.b "Bad Block_Checksum ...",$a,0
  10831. NotDOS_txt    dc.b "Not a DOS disk ...",$a,0
  10832. WriteProt_txt    dc.b "Disk is write-protected ...",$a,0
  10833. Bitmap_txt    dc.b "Invalid Bitmap ...",$a,0
  10834.  
  10835. NotEmpty_txt        dc.b "Directory not empty ...",$a,0
  10836. IDEerr_txt        dc.b "IDE disk error ...",$a,0
  10837. NoFFS_txt        dc.b "Not an FFS or Int. FFS disk ...",$a
  10838.             dc.b "(OFS and DC-FFS not supported)",$a,0
  10839. IllegalPath_txt        dc.b "Illegal path ...",$a,0
  10840. DeviceNotFound_txt    dc.b "Device not found ...",$a,0
  10841. FileExists_txt        dc.b "File already exists ...",$a,0
  10842. DiskFull_txt        dc.b "Disk full ...",$a,0
  10843. FileNotFound_txt    dc.b "File not found ...",$a,0
  10844. CreateFile_txt        dc.b "Can't create file ...",$a,0
  10845.  
  10846.  
  10847. unknown_txt        dc.b "Unknown command...",$a,0
  10848. illegal_syntax_txt    dc.b "Illegal syntax...",$a,0
  10849. illegal_addr_txt    dc.b "Illegal address...",$a,0
  10850. illegal_reg_txt        dc.b "Illegal register...",$a,0
  10851. illegal_val_txt        dc.b "Illegal value...",$a,0
  10852. illegal_name_txt    dc.b "Illegal name...",$a,0
  10853. illegal_string_txt    dc.b "Illegal string...",$a,0
  10854. illegal_expr_txt    dc.b "Illegal expression...",$a,0
  10855. not_found_txt        dc.b "File not found...",$a,0
  10856. too_break_txt        dc.b "Too many break points...",$a,0
  10857. insert_off_txt        dc.b "off"
  10858. insert_on_txt        dc.b "on "
  10859.  
  10860. outerr_txt    dc.b "Wrong register number...",$a,0
  10861.  
  10862.         include src/help.s
  10863.  
  10864. ;--------------------------------------------------------------------
  10865.  
  10866. topaz2        incbin "topaz3.raw"
  10867.         ;880*10 Main Font
  10868.  
  10869.         cnop 0,4
  10870.  
  10871. ***********************************************************
  10872.  
  10873.  
  10874. ascII_mac    macro
  10875.         dcb.b 80*(MAX_SCREEN-3),' '        ;fill with spc.
  10876.         dc.b "¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹"
  10877.         dc.b "¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹"
  10878.         dc.b "HRTmon V"
  10879.         version
  10880.         dc.b " by Alain Malek                         "
  10881.         dc.b "                      "
  10882.  
  10883.         dc.b \1
  10884.         dc.b "Track:[00] Drive:[0] Address:[$00000000]"
  10885.         dc.b " Hrt:[$00000000] Fcpu:[65802]  Ins:[Off]"
  10886.  
  10887.  
  10888.         even
  10889.         endm
  10890.  
  10891. ***********************************************************
  10892.  
  10893.         include src/format_block.s
  10894.         include src/custom_names.s
  10895.         include src/vector_names.s
  10896.  
  10897.  
  10898. **************************************************************************
  10899. **************************************************************************
  10900. **************************************************************************
  10901.  
  10902.         cnop 0,16
  10903.  
  10904. inited        dc.l 0            ;<>$12345678 then never entered
  10905. registres    dcb.l 14,0        ;d0-d7,a0-a5
  10906. a6_reg        dc.l 0
  10907. a7_reg        dc.l 0
  10908. sr_reg        dc.w 0
  10909. pc_reg        dc.l 0
  10910. ssp_reg        dc.l 0
  10911. usp_reg        dc.l 0
  10912. vbr_reg        dc.l 0
  10913. cacr_reg    dc.l 0
  10914. caar_reg    dc.l 0        ; or BUSR on 68060
  10915. isp_reg        dc.l 0
  10916. msp_reg        dc.l 0        ; or PCR on 68060
  10917. tc_reg        dc.l 0
  10918. end_registres
  10919. itt0_reg    dc.l 0
  10920. itt1_reg    dc.l 0
  10921. dtt0_reg    dc.l 0
  10922. dtt1_reg    dc.l 0
  10923.  
  10924.         cnop 0,4
  10925.  
  10926. OldRaster    dc.l 0            ;old pos of raster beam
  10927.  
  10928. proc_type    dc.w 2            ;processor type 2=68020,...,6=68060
  10929.     ;keyboard ptr with/without SHIFT, ALT
  10930. board_ptr    dc.l board3,board4,board4a
  10931.  
  10932. ;-------------------------------------------
  10933.  
  10934. ascII_ptr    dc.l ascII_page1    ;ptr on actual ascII page
  10935.         dc.l ascII_page1    ;list of ptrs on all ascII pages
  10936.         dc.l ascII_page2
  10937.         dc.l ascII_Tracer
  10938.         dc.l 0            ;end signal for multi-print
  10939.  
  10940. Reset_Flag    dc.w 0            ;Copy of Action_GAL AND %100
  10941. trace_count    dc.w 0            ;nb of steps to trace
  10942. escape        dc.b 0            ;escape monitor signal
  10943. no_kill        dc.b 0            ;don't kill AR on exit (for BP,trace..)
  10944. kill        dc.b 0            ;Kill cmd done
  10945. reboot        dc.b 0            ;Reboot cmd done
  10946. break_mode    dc.b 0            ;0=no break points -1 BP set
  10947. BP_reach    dc.b 0            ;entered from Illegal breakpoint
  10948. BPJ_reach    dc.b 0            ;entered from JSR breakpoint
  10949. BPatPC        dc.b 0            ;BP at PC -> need one trace step
  10950. trace_moni    dc.b 0            ;Tracer mode ON/OFF
  10951. cheat        dc.b 0            ;Can access Action-Replay area ?
  10952. cheat_cnt    dc.b 0            ;counter to enable cheat
  10953. pic_status    dc.b 0            ;0=low-mem ok. -1=pic in low-mem
  10954. VBL        dc.b 0            ;set to -1 at each VBL
  10955. packed        dc.b 0            ;used by LA_cmd
  10956. debug_entry    dc.b 0    ;1=bus,2=addr,3=illegal,4=zero,5=linea,6=linef
  10957. pcmcia_intena    dc.b 0            ;backup of pcmcia intena register
  10958.         cnop 0,4
  10959.  
  10960. corr_val    dc.l 0    ;offset to add to get the corrected address
  10961.             ;this is inited by the corr_addr procedure
  10962.  
  10963. ;-------------------------------------------
  10964.         cnop 0,4
  10965.  
  10966. last_cmd    dc.l cmd_list        ;keep last command
  10967. hex_ptr:    dc.l 0            ;ptr on last address shown as hexa
  10968. dis_ptr:    dc.l 0            ;ptr on last addr disassembled
  10969. asc_ptr        dc.l 0            ;same for ascII dump
  10970.  
  10971. time_repeat:    dc.w 0
  10972. time_cursor:    dc.w 0
  10973. cursor_x:    dc.w 0
  10974. cursor_y:    dc.w 0
  10975. old_cursor:    dc.l 0        ;cursor_xy backup for Tracer
  10976. print_cnt    dc.w 0        ;used in print procedure
  10977. ascII_num:    dcb.b 8,0
  10978. cursor_on:    dc.b 0        ;actual cursor state (displayed or not)
  10979. no_curs:    dc.b 0        ;disable cursor
  10980. key:        dc.b 0        ;actual key
  10981. key_prev:    dc.b $7f    ;previous key
  10982. shift_mode    dc.b 0        ;0=no shift key pressed
  10983. ctrl_mode    dc.b 0        ;0=no ctrl key pressed
  10984. alt_mode    dc.b 0        ;0=no alt key pressed
  10985. amiga_mode    dc.b 0        ;0=no amiga key pressed
  10986. insert_mode    dc.b 0        ;0=no insert -1=insert mode on
  10987. break        dc.b 0        ;break signal (ESC)
  10988. ascII_page    dc.b 0        ;0=page1, -1=page2
  10989.         even
  10990. nb_keys        dc.w 0
  10991. key_buffer    dcb.b 64,0
  10992. new_key        dc.b 0
  10993.         even
  10994.  
  10995. history_cnt    dc.w 0        ;last history
  10996. history_disp    dc.w 0        ;next displayed history
  10997. history        rept    16
  10998.         dcb.b 80,0
  10999.         endr        ;16 lines of history
  11000.  
  11001. command:    dcb.b 80+20,0        ;the actual command line is here
  11002.  
  11003. window_top    dc.w 0        ;top of actual window
  11004. window_bot    dc.w 0        ;bottom of actual window (last line)
  11005. screen_height    dc.w 22        ;nb max of lines (depending of resolution)
  11006.  
  11007.  
  11008. small_pic    dc.b 0        ;if -1 then only bottom of AR pic is displayed
  11009.                 ;(to get some more mem. for DMA-Disk buffer)
  11010. no_print    dc.b 0        ;if -1 then print won't write in the picture
  11011.                 ;memory, only in the ascII_page
  11012.  
  11013.         cnop 0,4
  11014.  
  11015. ;-------------- strings which are modified ----------------
  11016. registre_txt
  11017. data0_reg    dc.b "D0=xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx "
  11018. data4_reg    dc.b "xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx",$a
  11019. addr0_reg    dc.b "A0=xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx "
  11020. addr4_reg    dc.b "xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx",$a
  11021. pc_txt        dc.b "PC=xxxxxxxx  "
  11022. ssp_txt        dc.b "SSP=xxxxxxxx "
  11023. usp_txt        dc.b "USP=xxxxxxxx "
  11024. vbr_txt        dc.b "VBR=xxxxxxxx "
  11025. sr_txt        dc.b "SR=xxxx "
  11026. rts_txt        dc.b "RTS=xxxxxxxx",$a
  11027. ISP_txt        dc.b "ISP=xxxxxxxx "
  11028. MSP_txt        dc.b "MSP=xxxxxxxx "
  11029. CACR_txt    dc.b "CACR=xxxxxxxx "
  11030. CAAR_txt    dc.b "CAAR=xxxxxxxx "
  11031. mc_txt        dc.b "MC68060",$a,0
  11032.  
  11033. hex_txt:
  11034.     dc.b "h $xxxxxxxx $xxxx $xxxx $xxxx $xxxx $xxxx $xxxx $xxxx $xxxx "
  11035. hex_txt2    dc.b "'                '",$a,0
  11036.  
  11037.         cnop 0,4
  11038. general_txt    dcb.b 80,0    ;can be used by anyone to output a line
  11039.         dc.b $a,0
  11040.         even
  11041.  
  11042. ev_line        dcb.b 80,0    ;evaluation output line (for any other use too)
  11043.         dc.b $a,0
  11044.  
  11045. ;-------------- Tracer variables ---------------------
  11046.         cnop 0,4
  11047. tracer_old_rts    dc.l 0        ;when skiping subroutine
  11048. tracer_addr    dcb.l MAX_SCREEN-10,-1    ;address disassembled on each line
  11049.                 ;of the tracer
  11050.  
  11051. actual_pos    dc.w -1,-1
  11052. tracer_refresh    dc.b 0
  11053. trace_bsr    dc.b 0
  11054.  
  11055. ;-------------- watch variables ----------------------
  11056. watch_txt    dcb.b 12," "
  11057.  
  11058. watch        dc.l 0            ;the thing to watch, ptr or val
  11059.  
  11060. ;-------------- output cmd variables -----------------
  11061.         cnop 0,4
  11062. output_start    dc.l 0
  11063. output_ptr    dc.l 0
  11064.  
  11065.         cnop 0,4
  11066.  
  11067. ;-------------- Q (cmp mem) cmd variables ------------
  11068.  
  11069. cmp_start    dc.l 0
  11070. cmp_end        dc.l 0
  11071. cmp_dest    dc.l 0
  11072.  
  11073. ;-------------- A (assemble) cmd variables -----------
  11074.  
  11075. ass_addr    dc.l 0        ;address parameter
  11076.  
  11077. ;-------------- AF cmd variables ---------------------
  11078.  
  11079. af_ptr        dc.l 0
  11080.  
  11081. ;-------------- O (fill mem) cmd variables -----------
  11082.  
  11083. fill_start    dc.l 0
  11084. fill_end    dc.l 0
  11085.  
  11086. ;-------------- E show custom registers --------------
  11087.  
  11088. custom_offset    dc.l 0
  11089.  
  11090. ;-------------- trainer variables --------------------
  11091.  
  11092. ts_size        dc.w -1            ;size used for searching .B .W .L
  11093.         cnop 0,4
  11094. ts_start    dc.l 0
  11095. ts_end        dc.l 0
  11096.  
  11097. tf_txt        dc.b "$xxxxxxxx ",0
  11098. ts_deep        dc.b 0            ;deep trainer mode on/off
  11099.         cnop 0,4
  11100.  
  11101. ;-------------- DEBUG cmd variables ------------------
  11102.         cnop 0,4
  11103.  
  11104. exc8        dc.l 0            ;backup of
  11105. excC        dc.l 0            ;exception
  11106. exc10        dc.l 0            ;vectors
  11107. exc14        dc.l 0            ;when
  11108. exc28        dc.l 0            ;in
  11109. exc2C        dc.l 0            ;debug mode
  11110.  
  11111. debug        dc.b 0            ;debug mode ON/OFF
  11112.  
  11113. ;-------------- F,FI,FIF cmds variable ---------------
  11114.         cnop 0,4
  11115.  
  11116. find_start    dc.l 0
  11117. find_end    dc.l 0
  11118. find_list    dcb.b 80,0
  11119.         dc.w 0
  11120.  
  11121.         cnop 0,4
  11122.  
  11123. ;-------------- RS,WS cmds variables -----------------
  11124.  
  11125. sec_addr    dc.l 0
  11126.  
  11127. strtsec        dc.w 0
  11128. nbsec        dc.w 0
  11129.  
  11130. rwsec        dc.b 0        ;'R' or 'W' (rs or ws cmd)
  11131.         cnop 0,4
  11132.  
  11133. ;-------------- T,TA (trace) cmds variable -----------
  11134.  
  11135. old_trace:    dc.l 0        ;old trace exception vector
  11136. trace_address:    dc.l -1        ;used by TA
  11137.  
  11138. ;-------------- C,CE (copy,exg mem) cmd variables ----
  11139.  
  11140. copy_start    dc.l 0
  11141. copy_end    dc.l 0
  11142. copy_dest    dc.l 0
  11143. exgc        dc.b 0            ;copy or exg ?
  11144.         cnop 0,4
  11145.  
  11146. ;-------------- variables used by read_number procedure ---
  11147.  
  11148. minus        dc.b 0
  11149. ok_numb        dc.b 0
  11150. label        dc.b 0            ;disable label recognition
  11151.         cnop 0,4
  11152.  
  11153. ;-------------- variables used for evaluation --------
  11154.  
  11155. exit_stack    dc.l 0            ;to restore stack after an error
  11156. muls_data    dc.l 0,0        ;used by muls32 procedure
  11157. divs_data    dc.l 0,0        ;used by divs32 procedure
  11158. eval_size    dc.w 0            ;size 0=.b 1=.w 3=.l
  11159.         cnop 0,4
  11160.  
  11161. ;-------------- 65816 CPU variables ------------------
  11162.  
  11163. fami_mode    dc.b 0        ;0=65802 -1=65816
  11164. fami_auto    dc.b 0        ;automatic switch on/off   0/-1
  11165.         cnop 0,4
  11166.  
  11167. ;-------------- breakpoint variables -----------------
  11168.  
  11169. illegal_except    dc.l 0        ;old illegal exception vector for BP
  11170. Break_Address    dc.l 0        ;keep address of BP when entering monitor
  11171. JB_save        dc.l 0,0    ;used by JSR_reach
  11172.  
  11173. break_list    rept 20            ;20 breakpoints max.
  11174.  
  11175.         dc.l 0            ;break address
  11176.         dc.w -1            ;old word
  11177.         dc.l -1            ;old address for jsr
  11178.         endr
  11179.  
  11180.         dc.l -1            ;end
  11181.         dc.w -1            ;
  11182.         dc.l -1            ;signals
  11183.         cnop 0,4
  11184.  
  11185. ;-------------- variable used by get_dkey procedure --
  11186.  
  11187. dkey        dc.b 0,0        ;direct key,olddkey
  11188. dkey_rep    dc.w 0            ;direct key,repeat
  11189. dkey_shift    dc.b 0            ;direct shift
  11190.         cnop 0,4
  11191.  
  11192. ;-------------- Floppy disk variables ----------------
  11193.  
  11194. old_head    dc.w 0,0,0,0        ;old pos of head (1 for each drive)
  11195.  
  11196. sectpos:    dc.w 0            ;nb sectors to read in access
  11197. startsec:    dc.w 0            ;offset of first sector in 1st track
  11198. oldsectpos:    dc.w 0
  11199. oldstartsec:    dc.w 0
  11200.  
  11201. drive_present    dc.b 0,0,0,0        ;floppy drive present
  11202.  
  11203. drive:        dc.w 3            ;selected floppy disk (3-6)
  11204. track:        dc.w 0,0,0,0        ;actual pos of head (1 for each drive)
  11205. OldAdk:        dc.w 0
  11206. writes:        dc.b 0            ;write floppy accesss ?
  11207. init:        dc.b 0            ;head pos initied ? (bits 3-6)
  11208. mot_on:        dc.b 0            ;motor on ? (bits 3-6)
  11209. ctrl:        dc.b 0            ;end access signal
  11210.  
  11211.         cnop 0,4
  11212.  
  11213. header:        dc.l $ff00000b        ;MFM header
  11214. format        dc.b 0
  11215. first_sauve    dc.b 0
  11216.         cnop 0,4
  11217.  
  11218. drive_err    dc.w 0
  11219.  
  11220.         cnop 0,4
  11221.  
  11222. buffer        dc.l 0            ;address of DMA disk buffer
  11223.  
  11224. ;-------------- IDE drive variables ------------------
  11225.  
  11226.         STRUCTURE IDE_info,0
  11227.         UWORD II_NbCyl
  11228.         UWORD II_NbHeads
  11229.         UWORD II_NbSecTrack
  11230.         UWORD II_MultSize        ;multiple block size
  11231.         LABEL II_SIZEOF
  11232.  
  11233. IDE_info0    dc.w 0        ;NbCyl
  11234.         dc.w 0        ;NbHeads
  11235.         dc.w 0        ;NbSecTrack
  11236.         dc.w 0        ;MultSize
  11237.  
  11238. IDE_info1    dc.w 0        ;NbCyl
  11239.         dc.w 0        ;NbHeads
  11240.         dc.w 0        ;NbSecTrack
  11241.         dc.w 0        ;MultSize
  11242.  
  11243. IDE_IRQ        dc.b 0        ;set when IDE_interrupts found in level2
  11244.  
  11245.         even
  11246.  
  11247. ;-------------- part variables -----------------------
  11248.  
  11249.         cnop 0,4
  11250.  
  11251. floppy0:    dc.l 0
  11252.         dc.l 0
  11253.         dc.l 1760
  11254.         dc.l floppy_device
  11255.         dc.w 0            ;unit
  11256.         dc.b 0,0,0,0        ;for DOS\1,2,3,...
  11257.         dc.b 3,"DF0"
  11258.         dcb.b 32-4,0
  11259.         dcb.b 32,0
  11260. floppy1:    dc.l 0
  11261.         dc.l 0
  11262.         dc.l 1760
  11263.         dc.l floppy_device
  11264.         dc.w 1            ;unit
  11265.         dc.b 0,0,0,0        ;for DOS\1,2,3,...
  11266.         dc.b 3,"DF1"
  11267.         dcb.b 32-4,0
  11268.         dcb.b 32,0
  11269.  
  11270.         rept 16            ;16 harddisk partition max
  11271.         dc.l 0
  11272.         dc.l 0
  11273.         dc.l 0
  11274.         dc.l 0
  11275.         dc.w 0            ;unit
  11276.         dc.b 0,0,0,0        ;for DOS\1,2,3,...
  11277.         dcb.b 32,0
  11278.         dcb.b 32,0
  11279.         endr
  11280. harddisk_end
  11281.  
  11282.  
  11283. ;-------------- track buffer to speedup floppy access -----
  11284.  
  11285. track_buffer    dc.l 0        ;ptr on track buffer (11 sectors)
  11286. track_buffer_no    dc.w -1        ;no of track in track_buffer (0-159)-1=empty
  11287. track_sector    dcb.b 12,-1    ;-1 if sector of track_buffer isn't loaded
  11288.                 ;(12 values instead of 11 for easier clear)
  11289. flush_needed    dc.b 0
  11290.         cnop 0,4
  11291.  
  11292.  
  11293. ;------------------------------------------------
  11294.  
  11295. ascII_page1    ascII_mac "Page_1"
  11296. ascII_page2    ascII_mac "Page_2"
  11297. ascII_Tracer    ascII_mac "Tracer"
  11298.  
  11299. ;------------------------------------------------
  11300.         cnop 0,4
  11301.  
  11302. custom        dcb.w $100,0        ;copy of custom $DFF000-$DFF1FE
  11303.  
  11304. CIAA        dcb.b 16,0
  11305. CIAB        dcb.b 16,0
  11306.  
  11307. palette
  11308. paletteH    dcb.w 8*32,0        ;High bits
  11309. paletteL    dcb.w 8*32,0        ;Low bits
  11310.  
  11311. ;------------------------------------------------
  11312.  
  11313. fbuf1        rept nb_fbuf
  11314.         dcb.b 512,0        ;file buffers
  11315.         endr
  11316.  
  11317. backup_pic    dcb.b LOSIZE,0        ;backup of pic mem
  11318.  
  11319. ;------------------------------------------------
  11320.         cnop 0,4
  11321.  
  11322. tmp_mem_size    equ $8000
  11323. tmp_mem        dcb.b tmp_mem_size,0
  11324.  
  11325. ;tmp_mem is used by:
  11326. ; - Trainer commands
  11327. ; - copy command (copy a file)
  11328. ; - d2f command (disk to file) (uses 512*11 first bytes)
  11329. ; - f2d command (file to disk) (uses 512*11 first bytes)
  11330. ; - sa command (save all)
  11331. ; - la command (load all)
  11332. ; - sp command (save picture)
  11333. ; - test_CPU routine (uses first $400 bytes)
  11334.  
  11335. ;(!Trainer buffer can be erased by one of these commands!)
  11336.  
  11337.         dcb.b $800,0    ;stack area
  11338. stack
  11339.  
  11340. end
  11341.  
  11342. ;--------------------------------------------------------------------
  11343.  
  11344. ;max floppy filesize=1730*512=885760
  11345.  
  11346.